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

Bikeshed: many-to-many small follow-up #16

merged opened by bad-example.com targeting main from m2m-bikeshed

the derives came in from base64 in tangled#7, whic was removed.

the cursor is a composite, but we might have other composite cursors that are different -- renaming this one to reflect its specific purpose.

Labels

None yet.

Participants 1
AT URI
at://did:plc:hdhoaan3xa3jiuq4fg4mefid/sh.tangled.repo.pull/3mfk27yrzww22
+32 -29
Diff #0
+2 -2
constellation/src/lib.rs
··· 22 22 DeleteAccount(Did), 23 23 } 24 24 25 - #[derive(Debug, Hash, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)] 25 + #[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize)] 26 26 pub struct Did(pub String); 27 27 28 28 impl<T: Into<String>> From<T> for Did { ··· 31 31 } 32 32 } 33 33 34 - #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord)] 34 + #[derive(Debug, PartialEq, Serialize, Deserialize)] 35 35 pub struct RecordId { 36 36 pub did: Did, 37 37 pub collection: String,
+8 -3
constellation/src/server/mod.rs
··· 278 278 /// path to the secondary link in the linking record 279 279 path_to_other: String, 280 280 /// filter to linking records (join of the m2m) by these DIDs 281 + /// 282 + /// TODO: this should be called `link_did`, deprecate + add an alias 283 + /// TODO: should we have an `other_did` filter as well? 281 284 #[serde(default)] 282 285 did: Vec<String>, 283 286 /// filter to specific secondary records ··· 686 689 /// path to the secondary link in the linking record 687 690 path_to_other: String, 688 691 /// filter to linking records (join of the m2m) by these DIDs 692 + /// 693 + /// TODO: should we have an `other_did` filter as well? 689 694 #[serde(default)] 690 - did: Vec<String>, 695 + link_did: Vec<String>, 691 696 /// filter to specific secondary records 692 697 #[serde(default)] 693 698 other_subject: Vec<String>, ··· 695 700 #[serde(default = "get_default_cursor_limit")] 696 701 limit: u64, 697 702 } 698 - #[derive(Debug, Serialize, Clone)] 703 + #[derive(Debug, Serialize)] 699 704 struct ManyToManyItem { 700 705 link: RecordId, 701 706 subject: String, ··· 726 731 } 727 732 728 733 let filter_dids: HashSet<Did> = query 729 - .did 734 + .link_did 730 735 .iter() 731 736 .map(|d| d.trim()) 732 737 .filter(|d| !d.is_empty())
+7 -7
constellation/src/storage/mem_store.rs
··· 1 1 use super::{ 2 - LinkReader, LinkStorage, Order, PagedAppendingCollection, PagedOrderedCollection, StorageStats, 2 + LinkReader, LinkStorage, ManyToManyCursor, Order, PagedAppendingCollection, 3 + PagedOrderedCollection, StorageStats, 3 4 }; 4 - use crate::storage::CompositeCursor; 5 5 use crate::{ActionableEvent, CountsByCount, Did, RecordId}; 6 6 7 7 use anyhow::{anyhow, Result}; ··· 264 264 let f = f 265 265 .parse::<u64>() 266 266 .map_err(|e| anyhow!("invalid cursor.1: {e}"))?; 267 - Some(CompositeCursor { 268 - backward: b, 269 - forward: f, 267 + Some(ManyToManyCursor { 268 + backlink: b, 269 + forward_link: f, 270 270 }) 271 271 } 272 272 None => None, ··· 287 287 .iter() 288 288 .enumerate() 289 289 .filter_map(|(i, opt)| opt.as_ref().map(|v| (i, v))) 290 - .skip_while(|(linker_idx, _)| cursor.is_some_and(|c| *linker_idx < c.backward as usize)) 290 + .skip_while(|(linker_idx, _)| cursor.is_some_and(|c| *linker_idx < c.backlink as usize)) 291 291 .filter(|(_, (did, _))| filter_dids.is_empty() || filter_dids.contains(did)) 292 292 { 293 293 let Some(links) = data.links.get(did).and_then(|m| { ··· 308 308 }) 309 309 .skip_while(|(link_idx, _)| { 310 310 cursor.is_some_and(|c| { 311 - linker_idx == c.backward as usize && *link_idx <= c.forward as usize 311 + linker_idx == c.backlink as usize && *link_idx <= c.forward_link as usize 312 312 }) 313 313 }) 314 314 .take(limit as usize + 1 - items.len())
+3 -4
constellation/src/storage/mod.rs
··· 39 39 } 40 40 } 41 41 42 - // get-many-to-many composite cursor 43 42 #[derive(Copy, Clone, Debug)] 44 - struct CompositeCursor { 45 - backward: u64, 46 - forward: u64, 43 + struct ManyToManyCursor { 44 + backlink: u64, 45 + forward_link: u64, 47 46 } 48 47 49 48 /// A paged collection whose keys are sorted instead of indexed
+10 -11
constellation/src/storage/rocks_store.rs
··· 1 1 use super::{ 2 - ActionableEvent, LinkReader, LinkStorage, Order, PagedAppendingCollection, 2 + ActionableEvent, LinkReader, LinkStorage, ManyToManyCursor, Order, PagedAppendingCollection, 3 3 PagedOrderedCollection, StorageStats, 4 4 }; 5 - use crate::storage::CompositeCursor; 6 5 use crate::{CountsByCount, Did, RecordId}; 7 6 8 7 use anyhow::{anyhow, bail, Result}; ··· 946 945 path_to_other: &str, 947 946 limit: u64, 948 947 after: Option<String>, 949 - filter_dids: &HashSet<Did>, 948 + filter_link_dids: &HashSet<Did>, 950 949 filter_to_targets: &HashSet<String>, 951 950 ) -> Result<PagedOrderedCollection<(String, u64, u64), String>> { 952 951 let collection = Collection(collection.to_string()); ··· 966 965 return Ok(PagedOrderedCollection::empty()); 967 966 }; 968 967 969 - let filter_did_ids: HashMap<DidId, bool> = filter_dids 968 + let filter_did_ids: HashMap<DidId, bool> = filter_link_dids 970 969 .iter() 971 970 .filter_map(|did| self.did_id_table.get_id_val(&self.db, did).transpose()) 972 971 .collect::<Result<Vec<DidIdValue>>>()? ··· 1135 1134 path_to_other: &str, 1136 1135 limit: u64, 1137 1136 after: Option<String>, 1138 - filter_dids: &HashSet<Did>, 1137 + filter_link_dids: &HashSet<Did>, 1139 1138 filter_to_targets: &HashSet<String>, 1140 1139 ) -> Result<PagedOrderedCollection<(RecordId, String), String>> { 1141 1140 // helper to resolve dids ··· 1165 1164 let f = f 1166 1165 .parse::<u64>() 1167 1166 .map_err(|e| anyhow!("invalid cursor.1: {e}"))?; 1168 - Some(CompositeCursor { 1169 - backward: b, 1170 - forward: f, 1167 + Some(ManyToManyCursor { 1168 + backlink: b, 1169 + forward_link: f, 1171 1170 }) 1172 1171 } 1173 1172 None => None, ··· 1176 1175 eprintln!("cursor: {:#?}", cursor); 1177 1176 1178 1177 // (__active__) did ids and filter targets 1179 - let filter_did_ids: HashMap<DidId, bool> = filter_dids 1178 + let filter_did_ids: HashMap<DidId, bool> = filter_link_dids 1180 1179 .iter() 1181 1180 .filter_map(|did| self.did_id_table.get_id_val(&self.db, did).transpose()) 1182 1181 .collect::<Result<Vec<DidIdValue>>>()? ··· 1202 1201 // iterate backwards (who linked to the target?) 1203 1202 for (linker_idx, (did_id, rkey)) in 1204 1203 linkers.0.iter().enumerate().skip_while(|(linker_idx, _)| { 1205 - cursor.is_some_and(|c| *linker_idx < c.backward as usize) 1204 + cursor.is_some_and(|c| *linker_idx < c.backlink as usize) 1206 1205 }) 1207 1206 { 1208 1207 if did_id.is_empty() ··· 1233 1232 }) 1234 1233 .skip_while(|(link_idx, _)| { 1235 1234 cursor.is_some_and(|c| { 1236 - linker_idx == c.backward as usize && *link_idx <= c.forward as usize 1235 + linker_idx == c.backlink as usize && *link_idx <= c.forward_link as usize 1237 1236 }) 1238 1237 }) 1239 1238 .take(limit as usize + 1 - items.len())
+2 -2
constellation/templates/get-many-to-many.html.j2
··· 6 6 7 7 {% block content %} 8 8 9 - {% call try_it::get_many_to_many(query.subject, query.source, query.path_to_other, query.did, query.other_subject, query.limit) %} 9 + {% call try_it::get_many_to_many(query.subject, query.source, query.path_to_other, query.link_did, query.other_subject, query.limit) %} 10 10 11 11 <h2> 12 12 Many-to-many links to <code>{{ query.subject }}</code> ··· 36 36 <input type="hidden" name="subject" value="{{ query.subject }}" /> 37 37 <input type="hidden" name="source" value="{{ query.source }}" /> 38 38 <input type="hidden" name="pathToOther" value="{{ query.path_to_other }}" /> 39 - {% for did in query.did %} 39 + {% for did in query.link_did %} 40 40 <input type="hidden" name="did" value="{{ did }}" /> 41 41 {% endfor %} 42 42 {% for other in query.other_subject %}

History

5 rounds 0 comments
sign up or login to add to the discussion
6 commits
expand
clean up dervive traits, specific cursor name
bikeshed did filter name for m2m queries
remove some prints
ManyToManyItem and set default "try-it": listitems
update lexicon
add _idx suffix for clarity (thanks maxh!) +fwd->o
expand 0 comments
pull request successfully merged
5 commits
expand
clean up dervive traits, specific cursor name
bikeshed did filter name for m2m queries
remove some prints
ManyToManyItem and set default "try-it": listitems
update lexicon
expand 0 comments
5 commits
expand
clean up dervive traits, specific cursor name
bikeshed did filter name for m2m queries
remove some prints
ManyToManyItem and set default "try-it": listitems
update lexicon
expand 0 comments
4 commits
expand
clean up dervive traits, specific cursor name
bikeshed did filter name for m2m queries
remove some prints
ManyToManyItem and set default "try-it": listitems
expand 0 comments
bad-example.com submitted #0
2 commits
expand
clean up dervive traits, specific cursor name
bikeshed did filter name for m2m queries
expand 0 comments