diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-24 11:36:39 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-02-24 11:36:39 +0000 |
| commit | c31a313ccf781e54fa15942bc882c1b113d3f590 (patch) | |
| tree | 0dec673c40a7cff42651c290b8ded5f6d063a8ae /src/git | |
| parent | 5efdf431a1481f6fb7a17190b62588b81c5b1e65 (diff) | |
rename: fetch_repository_data -> fetch_repository_data_{excluding,with}_purgatory
The old name was ambiguous - it wasn't clear whether purgatory was
included or not. The two variants are now explicitly named:
- fetch_repository_data_excluding_purgatory: DB only
- fetch_repository_data_with_purgatory: DB + purgatory overlay
SyncContext trait method also renamed to fetch_repository_data_with_purgatory
to match the free function it delegates to.
Diffstat (limited to 'src/git')
| -rw-r--r-- | src/git/authorization.rs | 6 | ||||
| -rw-r--r-- | src/git/sync.rs | 45 |
2 files changed, 26 insertions, 25 deletions
diff --git a/src/git/authorization.rs b/src/git/authorization.rs index 0e9a8ba..bf49800 100644 --- a/src/git/authorization.rs +++ b/src/git/authorization.rs | |||
| @@ -234,7 +234,7 @@ pub struct RepositoryData { | |||
| 234 | /// | 234 | /// |
| 235 | /// This performs a single database query to fetch both announcement and state events, | 235 | /// This performs a single database query to fetch both announcement and state events, |
| 236 | /// which is more efficient than separate queries. | 236 | /// which is more efficient than separate queries. |
| 237 | pub async fn fetch_repository_data( | 237 | pub async fn fetch_repository_data_excluding_purgatory( |
| 238 | database: &SharedDatabase, | 238 | database: &SharedDatabase, |
| 239 | identifier: &str, | 239 | identifier: &str, |
| 240 | ) -> Result<RepositoryData> { | 240 | ) -> Result<RepositoryData> { |
| @@ -298,7 +298,7 @@ pub async fn fetch_repository_data_with_purgatory( | |||
| 298 | identifier: &str, | 298 | identifier: &str, |
| 299 | ) -> Result<RepositoryData> { | 299 | ) -> Result<RepositoryData> { |
| 300 | // First, fetch from database | 300 | // First, fetch from database |
| 301 | let mut repo_data = fetch_repository_data(database, identifier).await?; | 301 | let mut repo_data = fetch_repository_data_excluding_purgatory(database, identifier).await?; |
| 302 | 302 | ||
| 303 | // Then, add announcements from purgatory | 303 | // Then, add announcements from purgatory |
| 304 | let purgatory_announcements = purgatory.get_announcements_by_identifier(identifier); | 304 | let purgatory_announcements = purgatory.get_announcements_by_identifier(identifier); |
| @@ -511,7 +511,7 @@ pub async fn get_authorization_from_db( | |||
| 511 | identifier: &str, | 511 | identifier: &str, |
| 512 | ) -> Result<AuthorizationResult> { | 512 | ) -> Result<AuthorizationResult> { |
| 513 | // Fetch all repository data with a single query | 513 | // Fetch all repository data with a single query |
| 514 | let repo_data = fetch_repository_data(database, identifier).await?; | 514 | let repo_data = fetch_repository_data_excluding_purgatory(database, identifier).await?; |
| 515 | 515 | ||
| 516 | if repo_data.announcements.is_empty() { | 516 | if repo_data.announcements.is_empty() { |
| 517 | return Ok(AuthorizationResult::denied( | 517 | return Ok(AuthorizationResult::denied( |
diff --git a/src/git/sync.rs b/src/git/sync.rs index 0d9a6b5..9a02ad4 100644 --- a/src/git/sync.rs +++ b/src/git/sync.rs | |||
| @@ -38,8 +38,8 @@ use tracing::{debug, info, warn}; | |||
| 38 | use nostr_sdk::Event; | 38 | use nostr_sdk::Event; |
| 39 | 39 | ||
| 40 | use crate::git::authorization::{ | 40 | use crate::git::authorization::{ |
| 41 | collect_authorized_maintainers, fetch_repository_data, fetch_repository_data_with_purgatory, | 41 | collect_authorized_maintainers, fetch_repository_data_excluding_purgatory, |
| 42 | RepositoryData, | 42 | fetch_repository_data_with_purgatory, RepositoryData, |
| 43 | }; | 43 | }; |
| 44 | use crate::git::{self, oid_exists}; | 44 | use crate::git::{self, oid_exists}; |
| 45 | use crate::nostr::builder::{Nip34WritePolicy, SharedDatabase}; | 45 | use crate::nostr::builder::{Nip34WritePolicy, SharedDatabase}; |
| @@ -933,20 +933,21 @@ async fn process_purgatory_state_events( | |||
| 933 | // IMPORTANT: Use fetch_repository_data_with_purgatory to include announcements | 933 | // IMPORTANT: Use fetch_repository_data_with_purgatory to include announcements |
| 934 | // that may still be in purgatory (not yet promoted). This ensures authorization | 934 | // that may still be in purgatory (not yet promoted). This ensures authorization |
| 935 | // works correctly even if the announcement promotion happens in the same batch. | 935 | // works correctly even if the announcement promotion happens in the same batch. |
| 936 | let mut db_repo_data = match fetch_repository_data_with_purgatory(database, purgatory, identifier).await { | 936 | let mut db_repo_data = |
| 937 | Ok(data) => data, | 937 | match fetch_repository_data_with_purgatory(database, purgatory, identifier).await { |
| 938 | Err(e) => { | 938 | Ok(data) => data, |
| 939 | warn!( | 939 | Err(e) => { |
| 940 | identifier = %identifier, | 940 | warn!( |
| 941 | error = %e, | 941 | identifier = %identifier, |
| 942 | "Failed to fetch repository data for purgatory state events" | 942 | error = %e, |
| 943 | ); | 943 | "Failed to fetch repository data for purgatory state events" |
| 944 | result | 944 | ); |
| 945 | .errors | 945 | result |
| 946 | .push(format!("Failed to fetch repo data: {}", e)); | 946 | .errors |
| 947 | return result; | 947 | .push(format!("Failed to fetch repo data: {}", e)); |
| 948 | } | 948 | return result; |
| 949 | }; | 949 | } |
| 950 | }; | ||
| 950 | 951 | ||
| 951 | // Process each state event in chronological order | 952 | // Process each state event in chronological order |
| 952 | for entry in &purgatory_states { | 953 | for entry in &purgatory_states { |
| @@ -1231,7 +1232,7 @@ async fn process_purgatory_pr_events( | |||
| 1231 | // NOTE: Only fetch from database, NOT purgatory. PR events should only be | 1232 | // NOTE: Only fetch from database, NOT purgatory. PR events should only be |
| 1232 | // released from purgatory when the announcement has been promoted (validated). | 1233 | // released from purgatory when the announcement has been promoted (validated). |
| 1233 | // This ensures we don't accept PR events for announcements that fail validation. | 1234 | // This ensures we don't accept PR events for announcements that fail validation. |
| 1234 | let db_repo_data = match fetch_repository_data(database, identifier).await { | 1235 | let db_repo_data = match fetch_repository_data_excluding_purgatory(database, identifier).await { |
| 1235 | Ok(data) => data, | 1236 | Ok(data) => data, |
| 1236 | Err(e) => { | 1237 | Err(e) => { |
| 1237 | warn!( | 1238 | warn!( |
| @@ -1372,7 +1373,9 @@ async fn process_purgatory_announcements( | |||
| 1372 | error = %e, | 1373 | error = %e, |
| 1373 | "Failed to parse owner pubkey" | 1374 | "Failed to parse owner pubkey" |
| 1374 | ); | 1375 | ); |
| 1375 | result.errors.push(format!("Failed to parse owner pubkey: {}", e)); | 1376 | result |
| 1377 | .errors | ||
| 1378 | .push(format!("Failed to parse owner pubkey: {}", e)); | ||
| 1376 | return result; | 1379 | return result; |
| 1377 | } | 1380 | } |
| 1378 | }; | 1381 | }; |
| @@ -1450,10 +1453,8 @@ async fn process_purgatory_announcements( | |||
| 1450 | } | 1453 | } |
| 1451 | 1454 | ||
| 1452 | // Re-process events from hot cache | 1455 | // Re-process events from hot cache |
| 1453 | let dummy_addr = SocketAddr::new( | 1456 | let dummy_addr = |
| 1454 | IpAddr::V4(Ipv4Addr::LOCALHOST), | 1457 | SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 0); |
| 1455 | 0, | ||
| 1456 | ); | ||
| 1457 | for hot_event in hot_events { | 1458 | for hot_event in hot_events { |
| 1458 | info!( | 1459 | info!( |
| 1459 | event_id = %hot_event.id, | 1460 | event_id = %hot_event.id, |