diff options
Diffstat (limited to 'src/lib/client.rs')
| -rw-r--r-- | src/lib/client.rs | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/src/lib/client.rs b/src/lib/client.rs index 8a381ab..d9ba351 100644 --- a/src/lib/client.rs +++ b/src/lib/client.rs | |||
| @@ -179,14 +179,14 @@ impl Connect for Client { | |||
| 179 | 179 | ||
| 180 | let relay = self.client.relay(relay_url).await?; | 180 | let relay = self.client.relay(relay_url).await?; |
| 181 | 181 | ||
| 182 | if !relay.is_connected().await { | 182 | if !relay.is_connected() { |
| 183 | #[allow(clippy::large_futures)] | 183 | #[allow(clippy::large_futures)] |
| 184 | relay | 184 | relay |
| 185 | .connect(Some(std::time::Duration::from_secs(CONNECTION_TIMEOUT))) | 185 | .connect(Some(std::time::Duration::from_secs(CONNECTION_TIMEOUT))) |
| 186 | .await; | 186 | .await; |
| 187 | } | 187 | } |
| 188 | 188 | ||
| 189 | if !relay.is_connected().await { | 189 | if !relay.is_connected() { |
| 190 | bail!("connection timeout"); | 190 | bail!("connection timeout"); |
| 191 | } | 191 | } |
| 192 | Ok(()) | 192 | Ok(()) |
| @@ -615,26 +615,27 @@ async fn get_events_of( | |||
| 615 | ) -> Result<Vec<Event>> { | 615 | ) -> Result<Vec<Event>> { |
| 616 | // relay.reconcile(filter, opts).await?; | 616 | // relay.reconcile(filter, opts).await?; |
| 617 | 617 | ||
| 618 | if !relay.is_connected().await { | 618 | if !relay.is_connected() { |
| 619 | #[allow(clippy::large_futures)] | 619 | #[allow(clippy::large_futures)] |
| 620 | relay | 620 | relay |
| 621 | .connect(Some(std::time::Duration::from_secs(CONNECTION_TIMEOUT))) | 621 | .connect(Some(std::time::Duration::from_secs(CONNECTION_TIMEOUT))) |
| 622 | .await; | 622 | .await; |
| 623 | } | 623 | } |
| 624 | 624 | ||
| 625 | if !relay.is_connected().await { | 625 | if !relay.is_connected() { |
| 626 | bail!("connection timeout"); | 626 | bail!("connection timeout"); |
| 627 | } else if let Some(pb) = pb { | 627 | } else if let Some(pb) = pb { |
| 628 | pb.set_prefix(format!("connected {}", relay.url())); | 628 | pb.set_prefix(format!("connected {}", relay.url())); |
| 629 | } | 629 | } |
| 630 | let events = relay | 630 | let events = relay |
| 631 | .get_events_of( | 631 | .fetch_events( |
| 632 | filters, | 632 | filters, |
| 633 | // 20 is nostr_sdk default | 633 | // 20 is nostr_sdk default |
| 634 | std::time::Duration::from_secs(GET_EVENTS_TIMEOUT), | 634 | std::time::Duration::from_secs(GET_EVENTS_TIMEOUT), |
| 635 | nostr_sdk::FilterOptions::ExitOnEOSE, | 635 | nostr_sdk::FilterOptions::ExitOnEOSE, |
| 636 | ) | 636 | ) |
| 637 | .await?; | 637 | .await? |
| 638 | .to_vec(); | ||
| 638 | Ok(events) | 639 | Ok(events) |
| 639 | } | 640 | } |
| 640 | 641 | ||
| @@ -754,24 +755,26 @@ pub async fn get_events_from_cache( | |||
| 754 | git_repo_path: &Path, | 755 | git_repo_path: &Path, |
| 755 | filters: Vec<nostr::Filter>, | 756 | filters: Vec<nostr::Filter>, |
| 756 | ) -> Result<Vec<nostr::Event>> { | 757 | ) -> Result<Vec<nostr::Event>> { |
| 757 | get_local_cache_database(git_repo_path) | 758 | Ok(get_local_cache_database(git_repo_path) |
| 758 | .await? | 759 | .await? |
| 759 | .query(filters.clone()) | 760 | .query(filters.clone()) |
| 760 | .await | 761 | .await |
| 761 | .context( | 762 | .context( |
| 762 | "cannot execute query on opened git repo nostr cache database .git/nostr-cache.lmdb", | 763 | "cannot execute query on opened git repo nostr cache database .git/nostr-cache.lmdb", |
| 763 | ) | 764 | )? |
| 765 | .to_vec()) | ||
| 764 | } | 766 | } |
| 765 | 767 | ||
| 766 | pub async fn get_event_from_global_cache( | 768 | pub async fn get_event_from_global_cache( |
| 767 | git_repo_path: &Path, | 769 | git_repo_path: &Path, |
| 768 | filters: Vec<nostr::Filter>, | 770 | filters: Vec<nostr::Filter>, |
| 769 | ) -> Result<Vec<nostr::Event>> { | 771 | ) -> Result<Vec<nostr::Event>> { |
| 770 | get_global_cache_database(git_repo_path) | 772 | Ok(get_global_cache_database(git_repo_path) |
| 771 | .await? | 773 | .await? |
| 772 | .query(filters.clone()) | 774 | .query(filters.clone()) |
| 773 | .await | 775 | .await |
| 774 | .context("cannot execute query on opened ngit nostr cache database") | 776 | .context("cannot execute query on opened ngit nostr cache database")? |
| 777 | .to_vec()) | ||
| 775 | } | 778 | } |
| 776 | 779 | ||
| 777 | pub async fn save_event_in_cache(git_repo_path: &Path, event: &nostr::Event) -> Result<bool> { | 780 | pub async fn save_event_in_cache(git_repo_path: &Path, event: &nostr::Event) -> Result<bool> { |
| @@ -841,7 +844,7 @@ pub async fn get_repo_ref_from_cache( | |||
| 841 | events.insert( | 844 | events.insert( |
| 842 | Coordinate { | 845 | Coordinate { |
| 843 | kind: e.kind, | 846 | kind: e.kind, |
| 844 | identifier: e.identifier().unwrap().to_string(), | 847 | identifier: e.tags.identifier().unwrap().to_string(), |
| 845 | public_key: e.pubkey, | 848 | public_key: e.pubkey, |
| 846 | relays: vec![], | 849 | relays: vec![], |
| 847 | }, | 850 | }, |
| @@ -1114,7 +1117,7 @@ async fn process_fetched_events( | |||
| 1114 | .iter() | 1117 | .iter() |
| 1115 | .map(|(c, _)| c.clone()) | 1118 | .map(|(c, _)| c.clone()) |
| 1116 | .any(|c| { | 1119 | .any(|c| { |
| 1117 | c.identifier.eq(event.identifier().unwrap()) | 1120 | c.identifier.eq(event.tags.identifier().unwrap()) |
| 1118 | && c.public_key.eq(&event.pubkey) | 1121 | && c.public_key.eq(&event.pubkey) |
| 1119 | }); | 1122 | }); |
| 1120 | let update_to_existing = !new_coordinate | 1123 | let update_to_existing = !new_coordinate |
| @@ -1122,7 +1125,7 @@ async fn process_fetched_events( | |||
| 1122 | .repo_coordinates_without_relays | 1125 | .repo_coordinates_without_relays |
| 1123 | .iter() | 1126 | .iter() |
| 1124 | .any(|(c, t)| { | 1127 | .any(|(c, t)| { |
| 1125 | c.identifier.eq(event.identifier().unwrap()) | 1128 | c.identifier.eq(event.tags.identifier().unwrap()) |
| 1126 | && c.public_key.eq(&event.pubkey) | 1129 | && c.public_key.eq(&event.pubkey) |
| 1127 | && if let Some(t) = t { | 1130 | && if let Some(t) = t { |
| 1128 | event.created_at.gt(t) | 1131 | event.created_at.gt(t) |
| @@ -1135,7 +1138,7 @@ async fn process_fetched_events( | |||
| 1135 | Coordinate { | 1138 | Coordinate { |
| 1136 | kind: event.kind, | 1139 | kind: event.kind, |
| 1137 | public_key: event.pubkey, | 1140 | public_key: event.pubkey, |
| 1138 | identifier: event.identifier().unwrap().to_owned(), | 1141 | identifier: event.tags.identifier().unwrap().to_owned(), |
| 1139 | relays: vec![], | 1142 | relays: vec![], |
| 1140 | }, | 1143 | }, |
| 1141 | event.created_at, | 1144 | event.created_at, |
| @@ -1216,7 +1219,10 @@ async fn process_fetched_events( | |||
| 1216 | } | 1219 | } |
| 1217 | for event in &events { | 1220 | for event in &events { |
| 1218 | if !request.existing_events.contains(&event.id) | 1221 | if !request.existing_events.contains(&event.id) |
| 1219 | && !event.event_ids().any(|id| report.proposals.contains(id)) | 1222 | && !event |
| 1223 | .tags | ||
| 1224 | .event_ids() | ||
| 1225 | .any(|id| report.proposals.contains(id)) | ||
| 1220 | { | 1226 | { |
| 1221 | if event.kind.eq(&Kind::GitPatch) && !event_is_patch_set_root(event) { | 1227 | if event.kind.eq(&Kind::GitPatch) && !event_is_patch_set_root(event) { |
| 1222 | report.commits.insert(event.id); | 1228 | report.commits.insert(event.id); |