diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2024-07-16 13:44:37 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2024-07-16 13:44:37 +0100 |
| commit | a390dd5f94679111bd78ca28f623c18a6e5a59ff (patch) | |
| tree | 055d19a5aad0aa745ae6685cdb005289c2f22780 /src/client.rs | |
| parent | d11793cec610c6448e092a1ba55e7b79a5adeefb (diff) | |
fix(fetch): report details
so it only counts commits and statues to existing proposals
Diffstat (limited to 'src/client.rs')
| -rw-r--r-- | src/client.rs | 137 |
1 files changed, 70 insertions, 67 deletions
diff --git a/src/client.rs b/src/client.rs index d1001d0..8bdf3c2 100644 --- a/src/client.rs +++ b/src/client.rs | |||
| @@ -461,17 +461,15 @@ impl Connect for Client { | |||
| 461 | let events: Vec<nostr::Event> = get_events_of(&relay, filters, &None).await?; | 461 | let events: Vec<nostr::Event> = get_events_of(&relay, filters, &None).await?; |
| 462 | // TODO: try reconcile | 462 | // TODO: try reconcile |
| 463 | 463 | ||
| 464 | for event in events { | 464 | process_fetched_events( |
| 465 | process_fetched_event( | 465 | events, |
| 466 | event, | 466 | &request, |
| 467 | &request, | 467 | git_repo_path, |
| 468 | git_repo_path, | 468 | &mut fresh_coordinates, |
| 469 | &mut fresh_coordinates, | 469 | &mut fresh_proposal_roots, |
| 470 | &mut fresh_proposal_roots, | 470 | &mut report, |
| 471 | &mut report, | 471 | ) |
| 472 | ) | 472 | .await?; |
| 473 | .await?; | ||
| 474 | } | ||
| 475 | 473 | ||
| 476 | if fresh_coordinates.is_empty() && fresh_proposal_roots.is_empty() { | 474 | if fresh_coordinates.is_empty() && fresh_proposal_roots.is_empty() { |
| 477 | break; | 475 | break; |
| @@ -843,77 +841,82 @@ async fn create_relays_request( | |||
| 843 | }) | 841 | }) |
| 844 | } | 842 | } |
| 845 | 843 | ||
| 846 | async fn process_fetched_event( | 844 | async fn process_fetched_events( |
| 847 | event: nostr::Event, | 845 | events: Vec<nostr::Event>, |
| 848 | request: &FetchRequest, | 846 | request: &FetchRequest, |
| 849 | git_repo_path: &Path, | 847 | git_repo_path: &Path, |
| 850 | fresh_coordinates: &mut HashSet<Coordinate>, | 848 | fresh_coordinates: &mut HashSet<Coordinate>, |
| 851 | fresh_proposal_roots: &mut HashSet<EventId>, | 849 | fresh_proposal_roots: &mut HashSet<EventId>, |
| 852 | report: &mut FetchReport, | 850 | report: &mut FetchReport, |
| 853 | ) -> Result<()> { | 851 | ) -> Result<()> { |
| 854 | if !request.existing_events.contains(&event.id) { | 852 | for event in &events { |
| 855 | save_event_in_cache(git_repo_path, &event).await?; | 853 | if !request.existing_events.contains(&event.id) { |
| 856 | if event.kind().as_u16().eq(&REPO_REF_KIND) { | 854 | save_event_in_cache(git_repo_path, event).await?; |
| 857 | save_event_in_global_cache(git_repo_path, &event).await?; | 855 | if event.kind().as_u16().eq(&REPO_REF_KIND) { |
| 858 | let new_coordinate = !request.repo_coordinates.iter().any(|(c, _)| { | 856 | save_event_in_global_cache(git_repo_path, event).await?; |
| 859 | c.identifier.eq(event.identifier().unwrap()) && c.public_key.eq(&event.pubkey) | 857 | let new_coordinate = !request.repo_coordinates.iter().any(|(c, _)| { |
| 860 | }); | 858 | c.identifier.eq(event.identifier().unwrap()) && c.public_key.eq(&event.pubkey) |
| 861 | let update_to_existing = !new_coordinate | ||
| 862 | && request.repo_coordinates.iter().any(|(c, t)| { | ||
| 863 | c.identifier.eq(event.identifier().unwrap()) | ||
| 864 | && c.public_key.eq(&event.pubkey) | ||
| 865 | && if let Some(t) = t { | ||
| 866 | event.created_at.gt(t) | ||
| 867 | } else { | ||
| 868 | false | ||
| 869 | } | ||
| 870 | }); | 859 | }); |
| 871 | if new_coordinate || update_to_existing { | 860 | let update_to_existing = !new_coordinate |
| 872 | let c = Coordinate { | 861 | && request.repo_coordinates.iter().any(|(c, t)| { |
| 873 | kind: event.kind(), | 862 | c.identifier.eq(event.identifier().unwrap()) |
| 874 | public_key: event.author(), | 863 | && c.public_key.eq(&event.pubkey) |
| 875 | identifier: event.identifier().unwrap().to_string(), | 864 | && if let Some(t) = t { |
| 876 | relays: vec![], | 865 | event.created_at.gt(t) |
| 877 | }; | 866 | } else { |
| 878 | if new_coordinate { | 867 | false |
| 879 | fresh_coordinates.insert(c.clone()); | 868 | } |
| 880 | report.repo_coordinates.push(c.clone()); | 869 | }); |
| 881 | } | 870 | if new_coordinate || update_to_existing { |
| 882 | if update_to_existing { | 871 | let c = Coordinate { |
| 883 | report | 872 | kind: event.kind(), |
| 884 | .updated_repo_announcements | 873 | public_key: event.author(), |
| 885 | .push((c, event.created_at)); | 874 | identifier: event.identifier().unwrap().to_string(), |
| 875 | relays: vec![], | ||
| 876 | }; | ||
| 877 | if new_coordinate { | ||
| 878 | fresh_coordinates.insert(c.clone()); | ||
| 879 | report.repo_coordinates.push(c.clone()); | ||
| 880 | } | ||
| 881 | if update_to_existing { | ||
| 882 | report | ||
| 883 | .updated_repo_announcements | ||
| 884 | .push((c, event.created_at)); | ||
| 885 | } | ||
| 886 | } | 886 | } |
| 887 | } | 887 | // if contains new maintainer |
| 888 | // if contains new maintainer | 888 | if let Ok(repo_ref) = &RepoRef::try_from(event.clone()) { |
| 889 | if let Ok(repo_ref) = &RepoRef::try_from(event.clone()) { | 889 | for m in &repo_ref.maintainers { |
| 890 | for m in &repo_ref.maintainers { | 890 | if !request.repo_coordinates.iter().any(|(c, _)| { |
| 891 | if !request | 891 | c.identifier.eq(&repo_ref.identifier) && m.eq(&c.public_key) |
| 892 | .repo_coordinates | 892 | }) { |
| 893 | .iter() | 893 | fresh_coordinates.insert(Coordinate { |
| 894 | .any(|(c, _)| c.identifier.eq(&repo_ref.identifier) && m.eq(&c.public_key)) | 894 | kind: event.kind(), |
| 895 | { | 895 | public_key: *m, |
| 896 | fresh_coordinates.insert(Coordinate { | 896 | identifier: repo_ref.identifier.clone(), |
| 897 | kind: event.kind(), | 897 | relays: vec![], |
| 898 | public_key: *m, | 898 | }); |
| 899 | identifier: repo_ref.identifier.clone(), | 899 | } |
| 900 | relays: vec![], | ||
| 901 | }); | ||
| 902 | } | 900 | } |
| 903 | } | 901 | } |
| 902 | } else if event_is_patch_set_root(event) { | ||
| 903 | fresh_proposal_roots.insert(event.id); | ||
| 904 | report.proposals.insert(event.id); | ||
| 905 | } else if event.kind().eq(&nostr_sdk::Kind::Metadata) { | ||
| 906 | report.contributor_profiles.insert(event.author()); | ||
| 907 | save_event_in_global_cache(git_repo_path, event).await?; | ||
| 904 | } | 908 | } |
| 905 | } else if event_is_patch_set_root(&event) { | 909 | } |
| 906 | fresh_proposal_roots.insert(event.id); | 910 | } |
| 907 | report.proposals.insert(event.id); | 911 | for event in &events { |
| 908 | } else if !event.event_ids().any(|id| report.proposals.contains(id)) { | 912 | if !request.existing_events.contains(&event.id) |
| 909 | if event.kind().as_u16() == PATCH_KIND { | 913 | && !event.event_ids().any(|id| report.proposals.contains(id)) |
| 914 | { | ||
| 915 | if event.kind().as_u16() == PATCH_KIND && !event_is_patch_set_root(event) { | ||
| 910 | report.commits.insert(event.id); | 916 | report.commits.insert(event.id); |
| 911 | } else if status_kinds().contains(&event.kind()) { | 917 | } else if status_kinds().contains(&event.kind()) { |
| 912 | report.statuses.insert(event.id); | 918 | report.statuses.insert(event.id); |
| 913 | } | 919 | } |
| 914 | } else if event.kind().eq(&nostr_sdk::Kind::Metadata) { | ||
| 915 | report.contributor_profiles.insert(event.author()); | ||
| 916 | save_event_in_global_cache(git_repo_path, &event).await?; | ||
| 917 | } | 920 | } |
| 918 | } | 921 | } |
| 919 | Ok(()) | 922 | Ok(()) |