Constellation, Spacedust, Slingshot, UFOs: atproto crates and services for microcosm
75
fork

Configure Feed

Select the types of activity you want to include in your feed.

don't wrap the hashmap in option

phil 533c9eb3 710aa7b1

+90 -40
+2 -13
constellation/src/server/mod.rs
··· 271 271 return Err(http::StatusCode::BAD_REQUEST); 272 272 } 273 273 274 - // ugh could have just passed the zero-len hashmap through, same check in the impl 275 - // but now i feel lazy 276 - let empty = query.did.is_empty(); 277 - let dids = if !empty { 278 - None 279 - } else { 280 - let mut out = HashSet::new(); 281 - for d in &query.did { 282 - out.insert(Did(d.clone())); 283 - } 284 - Some(out) 285 - }; 274 + let filter_dids = HashSet::from_iter(query.did.iter().map(|d| Did(d.to_string()))); 286 275 287 276 let paged = store 288 277 .get_links( ··· 291 280 &query.path, 292 281 limit, 293 282 until, 294 - dids.as_ref(), 283 + &filter_dids, 295 284 ) 296 285 .map_err(|_| http::StatusCode::INTERNAL_SERVER_ERROR)?; 297 286
+3 -3
constellation/src/storage/mem_store.rs
··· 166 166 path: &str, 167 167 limit: u64, 168 168 until: Option<u64>, 169 - filter_dids: Option<&HashSet<Did>>, 169 + filter_dids: &HashSet<Did>, 170 170 ) -> Result<PagedAppendingCollection<RecordId>> { 171 171 let data = self.0.lock().unwrap(); 172 172 let Some(paths) = data.targets.get(&Target::new(target)) else { ··· 184 184 }); 185 185 }; 186 186 187 - let did_rkeys: Vec<_> = if let Some(dids) = filter_dids { 187 + let did_rkeys: Vec<_> = if !filter_dids.is_empty() { 188 188 did_rkeys 189 189 .iter() 190 190 .filter(|m| { 191 191 Option::<(Did, RKey)>::clone(m) 192 - .map(|(did, _)| dids.contains(&did)) 192 + .map(|(did, _)| filter_dids.contains(&did)) 193 193 .unwrap_or(false) 194 194 }) 195 195 .cloned()
+82 -21
constellation/src/storage/mod.rs
··· 58 58 path: &str, 59 59 limit: u64, 60 60 until: Option<u64>, 61 - filter_dids: Option<&HashSet<Did>>, 61 + filter_dids: &HashSet<Did>, 62 62 ) -> Result<PagedAppendingCollection<RecordId>>; 63 63 64 64 fn get_distinct_dids( ··· 145 145 ); 146 146 assert_eq!(storage.get_distinct_did_count("", "", "")?, 0); 147 147 assert_eq!( 148 - storage.get_links("a.com", "app.t.c", ".abc.uri", 100, None, None)?, 148 + storage.get_links( 149 + "a.com", 150 + "app.t.c", 151 + ".abc.uri", 152 + 100, 153 + None, 154 + &HashSet::default() 155 + )?, 149 156 PagedAppendingCollection { 150 157 version: (0, 0), 151 158 items: vec![], ··· 639 646 0, 640 647 )?; 641 648 assert_eq!( 642 - storage.get_links("a.com", "app.t.c", ".abc.uri", 100, None, None)?, 649 + storage.get_links( 650 + "a.com", 651 + "app.t.c", 652 + ".abc.uri", 653 + 100, 654 + None, 655 + &HashSet::default() 656 + )?, 643 657 PagedAppendingCollection { 644 658 version: (1, 0), 645 659 items: vec![RecordId { ··· 678 692 0, 679 693 )?; 680 694 } 681 - let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, None, None)?; 695 + let links = 696 + storage.get_links("a.com", "app.t.c", ".abc.uri", 2, None, &HashSet::default())?; 682 697 let dids = storage.get_distinct_dids("a.com", "app.t.c", ".abc.uri", 2, None)?; 683 698 assert_eq!( 684 699 links, ··· 707 722 next: Some(3), 708 723 } 709 724 ); 710 - let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, links.next, None)?; 725 + let links = storage.get_links( 726 + "a.com", 727 + "app.t.c", 728 + ".abc.uri", 729 + 2, 730 + links.next, 731 + &HashSet::default(), 732 + )?; 711 733 let dids = storage.get_distinct_dids("a.com", "app.t.c", ".abc.uri", 2, dids.next)?; 712 734 assert_eq!( 713 735 links, ··· 736 758 next: Some(1), 737 759 } 738 760 ); 739 - let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, links.next, None)?; 761 + let links = storage.get_links( 762 + "a.com", 763 + "app.t.c", 764 + ".abc.uri", 765 + 2, 766 + links.next, 767 + &HashSet::default(), 768 + )?; 740 769 let dids = storage.get_distinct_dids("a.com", "app.t.c", ".abc.uri", 2, dids.next)?; 741 770 assert_eq!( 742 771 links, ··· 768 797 ".abc.uri", 769 798 2, 770 799 None, 771 - Some(&HashSet::from([Did("did:plc:linker".to_string())])), 800 + &HashSet::from([Did("did:plc:linker".to_string())]), 772 801 )?; 773 802 assert_eq!( 774 803 links, ··· 800 829 ".abc.uri", 801 830 2, 802 831 None, 803 - Some(&HashSet::from([Did("did:plc:linker".to_string())])), 832 + &HashSet::from([Did("did:plc:linker".to_string())]), 804 833 )?; 805 834 assert_eq!( 806 835 links, ··· 821 850 ".abc.uri", 822 851 2, 823 852 None, 824 - Some(&HashSet::from([Did("did:plc:someone-else".to_string())])), 853 + &HashSet::from([Did("did:plc:someone-else".to_string())]), 825 854 )?; 826 855 assert_eq!( 827 856 links, ··· 867 896 ".abc.uri", 868 897 2, 869 898 None, 870 - Some(&HashSet::from([Did("did:plc:linker".to_string())])), 899 + &HashSet::from([Did("did:plc:linker".to_string())]), 871 900 )?; 872 901 assert_eq!( 873 902 links, ··· 895 924 ".abc.uri", 896 925 2, 897 926 None, 898 - Some(&HashSet::from([ 927 + &HashSet::from([ 899 928 Did("did:plc:linker".to_string()), 900 929 Did("did:plc:someone-else".to_string()), 901 - ])), 930 + ]), 902 931 )?; 903 932 assert_eq!( 904 933 links, ··· 926 955 ".abc.uri", 927 956 2, 928 957 None, 929 - Some(&HashSet::from([Did("did:plc:someone-unknown".to_string())])), 958 + &HashSet::from([Did("did:plc:someone-unknown".to_string())]), 930 959 )?; 931 960 assert_eq!( 932 961 links, ··· 955 984 0, 956 985 )?; 957 986 } 958 - let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, None, None)?; 987 + let links = 988 + storage.get_links("a.com", "app.t.c", ".abc.uri", 2, None, &HashSet::default())?; 959 989 assert_eq!( 960 990 links, 961 991 PagedAppendingCollection { ··· 975 1005 next: Some(2), 976 1006 } 977 1007 ); 978 - let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, links.next, None)?; 1008 + let links = storage.get_links( 1009 + "a.com", 1010 + "app.t.c", 1011 + ".abc.uri", 1012 + 2, 1013 + links.next, 1014 + &HashSet::default(), 1015 + )?; 979 1016 assert_eq!( 980 1017 links, 981 1018 PagedAppendingCollection { ··· 1015 1052 0, 1016 1053 )?; 1017 1054 } 1018 - let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, None, None)?; 1055 + let links = 1056 + storage.get_links("a.com", "app.t.c", ".abc.uri", 2, None, &HashSet::default())?; 1019 1057 assert_eq!( 1020 1058 links, 1021 1059 PagedAppendingCollection { ··· 1049 1087 }, 1050 1088 0, 1051 1089 )?; 1052 - let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, links.next, None)?; 1090 + let links = storage.get_links( 1091 + "a.com", 1092 + "app.t.c", 1093 + ".abc.uri", 1094 + 2, 1095 + links.next, 1096 + &HashSet::default(), 1097 + )?; 1053 1098 assert_eq!( 1054 1099 links, 1055 1100 PagedAppendingCollection { ··· 1089 1134 0, 1090 1135 )?; 1091 1136 } 1092 - let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, None, None)?; 1137 + let links = 1138 + storage.get_links("a.com", "app.t.c", ".abc.uri", 2, None, &HashSet::default())?; 1093 1139 assert_eq!( 1094 1140 links, 1095 1141 PagedAppendingCollection { ··· 1117 1163 }), 1118 1164 0, 1119 1165 )?; 1120 - let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, links.next, None)?; 1166 + let links = storage.get_links( 1167 + "a.com", 1168 + "app.t.c", 1169 + ".abc.uri", 1170 + 2, 1171 + links.next, 1172 + &HashSet::default(), 1173 + )?; 1121 1174 assert_eq!( 1122 1175 links, 1123 1176 PagedAppendingCollection { ··· 1150 1203 0, 1151 1204 )?; 1152 1205 } 1153 - let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, None, None)?; 1206 + let links = 1207 + storage.get_links("a.com", "app.t.c", ".abc.uri", 2, None, &HashSet::default())?; 1154 1208 assert_eq!( 1155 1209 links, 1156 1210 PagedAppendingCollection { ··· 1174 1228 &ActionableEvent::DeactivateAccount("did:plc:asdf-1".into()), 1175 1229 0, 1176 1230 )?; 1177 - let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, links.next, None)?; 1231 + let links = storage.get_links( 1232 + "a.com", 1233 + "app.t.c", 1234 + ".abc.uri", 1235 + 2, 1236 + links.next, 1237 + &HashSet::default(), 1238 + )?; 1178 1239 assert_eq!( 1179 1240 links, 1180 1241 PagedAppendingCollection {
+3 -3
constellation/src/storage/rocks_store.rs
··· 860 860 path: &str, 861 861 limit: u64, 862 862 until: Option<u64>, 863 - filter_dids: Option<&HashSet<Did>>, 863 + filter_dids: &HashSet<Did>, 864 864 ) -> Result<PagedAppendingCollection<RecordId>> { 865 865 let target_key = TargetKey( 866 866 Target(target.to_string()), ··· 877 877 }; 878 878 879 879 let mut linkers = self.get_target_linkers(&target_id)?; 880 - if let Some(dids) = filter_dids { 880 + if !filter_dids.is_empty() { 881 881 let mut did_filter = HashSet::new(); 882 - for did in dids { 882 + for did in filter_dids { 883 883 let Some(DidIdValue(did_id, active)) = 884 884 self.did_id_table.get_id_val(&self.db, did)? 885 885 else {