diff options
| -rw-r--r-- | src/client.rs | 102 | ||||
| -rw-r--r-- | src/repo_ref.rs | 2 |
2 files changed, 60 insertions, 44 deletions
diff --git a/src/client.rs b/src/client.rs index 4f002fb..0757359 100644 --- a/src/client.rs +++ b/src/client.rs | |||
| @@ -345,7 +345,7 @@ impl Connect for Client { | |||
| 345 | // if relay isn't a repo relay, just filter for user profile | 345 | // if relay isn't a repo relay, just filter for user profile |
| 346 | FetchRequest { | 346 | FetchRequest { |
| 347 | selected_relay: Some(r.to_owned()), | 347 | selected_relay: Some(r.to_owned()), |
| 348 | repo_coordinates: vec![], | 348 | repo_coordinates_without_relays: vec![], |
| 349 | proposals: HashSet::new(), | 349 | proposals: HashSet::new(), |
| 350 | missing_contributor_profiles: request | 350 | missing_contributor_profiles: request |
| 351 | .missing_contributor_profiles | 351 | .missing_contributor_profiles |
| @@ -464,11 +464,11 @@ impl Connect for Client { | |||
| 464 | pb: &Option<ProgressBar>, | 464 | pb: &Option<ProgressBar>, |
| 465 | ) -> Result<FetchReport> { | 465 | ) -> Result<FetchReport> { |
| 466 | let mut fresh_coordinates: HashSet<Coordinate> = HashSet::new(); | 466 | let mut fresh_coordinates: HashSet<Coordinate> = HashSet::new(); |
| 467 | for (c, _) in request.repo_coordinates.clone() { | 467 | for (c, _) in request.repo_coordinates_without_relays.clone() { |
| 468 | fresh_coordinates.insert(c); | 468 | fresh_coordinates.insert(c); |
| 469 | } | 469 | } |
| 470 | let mut fresh_proposal_roots = request.proposals.clone(); | 470 | let mut fresh_proposal_roots = request.proposals.clone(); |
| 471 | let mut fresh_profiles = request | 471 | let mut fresh_profiles: HashSet<PublicKey> = request |
| 472 | .missing_contributor_profiles | 472 | .missing_contributor_profiles |
| 473 | .union( | 473 | .union( |
| 474 | &request | 474 | &request |
| @@ -1006,7 +1006,7 @@ async fn create_relays_request( | |||
| 1006 | selected_relay: None, | 1006 | selected_relay: None, |
| 1007 | repo_relays: relays, | 1007 | repo_relays: relays, |
| 1008 | relay_column_width, | 1008 | relay_column_width, |
| 1009 | repo_coordinates: if let Ok(repo_ref) = repo_ref { | 1009 | repo_coordinates_without_relays: if let Ok(repo_ref) = repo_ref { |
| 1010 | repo_ref.coordinates_with_timestamps() | 1010 | repo_ref.coordinates_with_timestamps() |
| 1011 | } else { | 1011 | } else { |
| 1012 | repo_coordinates_without_relays | 1012 | repo_coordinates_without_relays |
| @@ -1038,48 +1038,58 @@ async fn process_fetched_events( | |||
| 1038 | save_event_in_cache(git_repo_path, event).await?; | 1038 | save_event_in_cache(git_repo_path, event).await?; |
| 1039 | if event.kind().as_u16().eq(&REPO_REF_KIND) { | 1039 | if event.kind().as_u16().eq(&REPO_REF_KIND) { |
| 1040 | save_event_in_global_cache(git_repo_path, event).await?; | 1040 | save_event_in_global_cache(git_repo_path, event).await?; |
| 1041 | let new_coordinate = !request.repo_coordinates.iter().any(|(c, _)| { | 1041 | let new_coordinate = !request |
| 1042 | c.identifier.eq(event.identifier().unwrap()) && c.public_key.eq(&event.pubkey) | 1042 | .repo_coordinates_without_relays |
| 1043 | }); | 1043 | .iter() |
| 1044 | let update_to_existing = !new_coordinate | 1044 | .map(|(c, _)| c.clone()) |
| 1045 | && request.repo_coordinates.iter().any(|(c, t)| { | 1045 | .any(|c| { |
| 1046 | c.identifier.eq(event.identifier().unwrap()) | 1046 | c.identifier.eq(event.identifier().unwrap()) |
| 1047 | && c.public_key.eq(&event.pubkey) | 1047 | && c.public_key.eq(&event.pubkey) |
| 1048 | && if let Some(t) = t { | ||
| 1049 | event.created_at.gt(t) | ||
| 1050 | } else { | ||
| 1051 | false | ||
| 1052 | } | ||
| 1053 | }); | 1048 | }); |
| 1054 | if new_coordinate || update_to_existing { | 1049 | let update_to_existing = !new_coordinate |
| 1055 | let c = Coordinate { | 1050 | && request |
| 1056 | kind: event.kind(), | 1051 | .repo_coordinates_without_relays |
| 1057 | public_key: event.author(), | 1052 | .iter() |
| 1058 | identifier: event.identifier().unwrap().to_string(), | 1053 | .any(|(c, t)| { |
| 1059 | relays: vec![], | 1054 | c.identifier.eq(event.identifier().unwrap()) |
| 1060 | }; | 1055 | && c.public_key.eq(&event.pubkey) |
| 1061 | if new_coordinate { | 1056 | && if let Some(t) = t { |
| 1062 | fresh_coordinates.insert(c.clone()); | 1057 | event.created_at.gt(t) |
| 1063 | report.repo_coordinates.push(c.clone()); | 1058 | } else { |
| 1064 | } | 1059 | true |
| 1065 | if update_to_existing { | 1060 | } |
| 1066 | report | 1061 | }); |
| 1067 | .updated_repo_announcements | 1062 | if update_to_existing { |
| 1068 | .push((c, event.created_at)); | 1063 | report.updated_repo_announcements.push(( |
| 1069 | } | 1064 | Coordinate { |
| 1065 | kind: event.kind(), | ||
| 1066 | public_key: event.author(), | ||
| 1067 | identifier: event.identifier().unwrap().to_owned(), | ||
| 1068 | relays: vec![], | ||
| 1069 | }, | ||
| 1070 | event.created_at, | ||
| 1071 | )); | ||
| 1070 | } | 1072 | } |
| 1071 | // if contains new maintainer | 1073 | // if contains new maintainer |
| 1072 | if let Ok(repo_ref) = &RepoRef::try_from(event.clone()) { | 1074 | if let Ok(repo_ref) = &RepoRef::try_from(event.clone()) { |
| 1073 | for m in &repo_ref.maintainers { | 1075 | for m in &repo_ref.maintainers { |
| 1074 | if !request.repo_coordinates.iter().any(|(c, _)| { | 1076 | if !request |
| 1075 | c.identifier.eq(&repo_ref.identifier) && m.eq(&c.public_key) | 1077 | .repo_coordinates_without_relays // prexisting maintainers |
| 1076 | }) { | 1078 | .iter() |
| 1077 | fresh_coordinates.insert(Coordinate { | 1079 | .map(|(c, _)| c.clone()) |
| 1080 | .collect::<HashSet<Coordinate>>() | ||
| 1081 | .union(&report.repo_coordinates_without_relays) // already added maintainers | ||
| 1082 | .any(|c| c.identifier.eq(&repo_ref.identifier) && m.eq(&c.public_key)) | ||
| 1083 | { | ||
| 1084 | let c = Coordinate { | ||
| 1078 | kind: event.kind(), | 1085 | kind: event.kind(), |
| 1079 | public_key: *m, | 1086 | public_key: *m, |
| 1080 | identifier: repo_ref.identifier.clone(), | 1087 | identifier: repo_ref.identifier.clone(), |
| 1081 | relays: vec![], | 1088 | relays: vec![], |
| 1082 | }); | 1089 | }; |
| 1090 | fresh_coordinates.insert(c.clone()); | ||
| 1091 | report.repo_coordinates_without_relays.insert(c); | ||
| 1092 | |||
| 1083 | if !request.contributors.contains(m) | 1093 | if !request.contributors.contains(m) |
| 1084 | && !request | 1094 | && !request |
| 1085 | .profiles_to_fetch_from_user_relays | 1095 | .profiles_to_fetch_from_user_relays |
| @@ -1141,9 +1151,13 @@ async fn process_fetched_events( | |||
| 1141 | pub fn consolidate_fetch_reports(reports: Vec<Result<FetchReport>>) -> FetchReport { | 1151 | pub fn consolidate_fetch_reports(reports: Vec<Result<FetchReport>>) -> FetchReport { |
| 1142 | let mut report = FetchReport::default(); | 1152 | let mut report = FetchReport::default(); |
| 1143 | for relay_report in reports.into_iter().flatten() { | 1153 | for relay_report in reports.into_iter().flatten() { |
| 1144 | for c in relay_report.repo_coordinates { | 1154 | for c in relay_report.repo_coordinates_without_relays { |
| 1145 | if !report.repo_coordinates.iter().any(|e| e.eq(&c)) { | 1155 | if !report |
| 1146 | report.repo_coordinates.push(c); | 1156 | .repo_coordinates_without_relays |
| 1157 | .iter() | ||
| 1158 | .any(|e| e.eq(&c)) | ||
| 1159 | { | ||
| 1160 | report.repo_coordinates_without_relays.insert(c); | ||
| 1147 | } | 1161 | } |
| 1148 | } | 1162 | } |
| 1149 | for (r, t) in relay_report.updated_repo_announcements { | 1163 | for (r, t) in relay_report.updated_repo_announcements { |
| @@ -1247,7 +1261,7 @@ pub fn get_filter_contributor_profiles(contributors: HashSet<PublicKey>) -> nost | |||
| 1247 | 1261 | ||
| 1248 | #[derive(Default)] | 1262 | #[derive(Default)] |
| 1249 | pub struct FetchReport { | 1263 | pub struct FetchReport { |
| 1250 | repo_coordinates: Vec<Coordinate>, | 1264 | repo_coordinates_without_relays: HashSet<Coordinate>, |
| 1251 | updated_repo_announcements: Vec<(Coordinate, Timestamp)>, | 1265 | updated_repo_announcements: Vec<(Coordinate, Timestamp)>, |
| 1252 | proposals: HashSet<EventId>, | 1266 | proposals: HashSet<EventId>, |
| 1253 | /// commits against existing propoals | 1267 | /// commits against existing propoals |
| @@ -1261,11 +1275,11 @@ impl Display for FetchReport { | |||
| 1261 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | 1275 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 1262 | // report: "1 new maintainer, 1 announcement, 1 proposal, 3 commits, 2 statuses" | 1276 | // report: "1 new maintainer, 1 announcement, 1 proposal, 3 commits, 2 statuses" |
| 1263 | let mut display_items: Vec<String> = vec![]; | 1277 | let mut display_items: Vec<String> = vec![]; |
| 1264 | if !self.repo_coordinates.is_empty() { | 1278 | if !self.repo_coordinates_without_relays.is_empty() { |
| 1265 | display_items.push(format!( | 1279 | display_items.push(format!( |
| 1266 | "{} new maintainer{}", | 1280 | "{} new maintainer{}", |
| 1267 | self.repo_coordinates.len(), | 1281 | self.repo_coordinates_without_relays.len(), |
| 1268 | if self.repo_coordinates.len() == 1 { | 1282 | if self.repo_coordinates_without_relays.len() > 1 { |
| 1269 | "s" | 1283 | "s" |
| 1270 | } else { | 1284 | } else { |
| 1271 | "" | 1285 | "" |
| @@ -1276,7 +1290,7 @@ impl Display for FetchReport { | |||
| 1276 | display_items.push(format!( | 1290 | display_items.push(format!( |
| 1277 | "{} announcement update{}", | 1291 | "{} announcement update{}", |
| 1278 | self.updated_repo_announcements.len(), | 1292 | self.updated_repo_announcements.len(), |
| 1279 | if self.updated_repo_announcements.len() == 1 { | 1293 | if self.updated_repo_announcements.len() > 1 { |
| 1280 | "s" | 1294 | "s" |
| 1281 | } else { | 1295 | } else { |
| 1282 | "" | 1296 | "" |
| @@ -1335,7 +1349,7 @@ pub struct FetchRequest { | |||
| 1335 | repo_relays: HashSet<Url>, | 1349 | repo_relays: HashSet<Url>, |
| 1336 | selected_relay: Option<Url>, | 1350 | selected_relay: Option<Url>, |
| 1337 | relay_column_width: usize, | 1351 | relay_column_width: usize, |
| 1338 | repo_coordinates: Vec<(Coordinate, Option<Timestamp>)>, | 1352 | repo_coordinates_without_relays: Vec<(Coordinate, Option<Timestamp>)>, |
| 1339 | proposals: HashSet<EventId>, | 1353 | proposals: HashSet<EventId>, |
| 1340 | contributors: HashSet<PublicKey>, | 1354 | contributors: HashSet<PublicKey>, |
| 1341 | missing_contributor_profiles: HashSet<PublicKey>, | 1355 | missing_contributor_profiles: HashSet<PublicKey>, |
diff --git a/src/repo_ref.rs b/src/repo_ref.rs index df348a5..9bc3201 100644 --- a/src/repo_ref.rs +++ b/src/repo_ref.rs | |||
| @@ -178,6 +178,7 @@ impl RepoRef { | |||
| 178 | .await | 178 | .await |
| 179 | .context("failed to create repository reference event") | 179 | .context("failed to create repository reference event") |
| 180 | } | 180 | } |
| 181 | /// coordinates without relay hints | ||
| 181 | pub fn coordinates(&self) -> HashSet<Coordinate> { | 182 | pub fn coordinates(&self) -> HashSet<Coordinate> { |
| 182 | let mut res = HashSet::new(); | 183 | let mut res = HashSet::new(); |
| 183 | for m in &self.maintainers { | 184 | for m in &self.maintainers { |
| @@ -190,6 +191,7 @@ impl RepoRef { | |||
| 190 | } | 191 | } |
| 191 | res | 192 | res |
| 192 | } | 193 | } |
| 194 | /// coordinates without relay hints | ||
| 193 | pub fn coordinates_with_timestamps(&self) -> Vec<(Coordinate, Option<Timestamp>)> { | 195 | pub fn coordinates_with_timestamps(&self) -> Vec<(Coordinate, Option<Timestamp>)> { |
| 194 | self.coordinates() | 196 | self.coordinates() |
| 195 | .iter() | 197 | .iter() |