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

don't wrap the hashmap in option

Changed files
+90 -40
constellation
+2 -13
constellation/src/server/mod.rs
···
return Err(http::StatusCode::BAD_REQUEST);
}
-
// ugh could have just passed the zero-len hashmap through, same check in the impl
-
// but now i feel lazy
-
let empty = query.did.is_empty();
-
let dids = if !empty {
-
None
-
} else {
-
let mut out = HashSet::new();
-
for d in &query.did {
-
out.insert(Did(d.clone()));
-
}
-
Some(out)
-
};
+
let filter_dids = HashSet::from_iter(query.did.iter().map(|d| Did(d.to_string())));
let paged = store
.get_links(
···
&query.path,
limit,
until,
-
dids.as_ref(),
+
&filter_dids,
)
.map_err(|_| http::StatusCode::INTERNAL_SERVER_ERROR)?;
+3 -3
constellation/src/storage/mem_store.rs
···
path: &str,
limit: u64,
until: Option<u64>,
-
filter_dids: Option<&HashSet<Did>>,
+
filter_dids: &HashSet<Did>,
) -> Result<PagedAppendingCollection<RecordId>> {
let data = self.0.lock().unwrap();
let Some(paths) = data.targets.get(&Target::new(target)) else {
···
});
};
-
let did_rkeys: Vec<_> = if let Some(dids) = filter_dids {
+
let did_rkeys: Vec<_> = if !filter_dids.is_empty() {
did_rkeys
.iter()
.filter(|m| {
Option::<(Did, RKey)>::clone(m)
-
.map(|(did, _)| dids.contains(&did))
+
.map(|(did, _)| filter_dids.contains(&did))
.unwrap_or(false)
})
.cloned()
+82 -21
constellation/src/storage/mod.rs
···
path: &str,
limit: u64,
until: Option<u64>,
-
filter_dids: Option<&HashSet<Did>>,
+
filter_dids: &HashSet<Did>,
) -> Result<PagedAppendingCollection<RecordId>>;
fn get_distinct_dids(
···
);
assert_eq!(storage.get_distinct_did_count("", "", "")?, 0);
assert_eq!(
-
storage.get_links("a.com", "app.t.c", ".abc.uri", 100, None, None)?,
+
storage.get_links(
+
"a.com",
+
"app.t.c",
+
".abc.uri",
+
100,
+
None,
+
&HashSet::default()
+
)?,
PagedAppendingCollection {
version: (0, 0),
items: vec![],
···
0,
)?;
assert_eq!(
-
storage.get_links("a.com", "app.t.c", ".abc.uri", 100, None, None)?,
+
storage.get_links(
+
"a.com",
+
"app.t.c",
+
".abc.uri",
+
100,
+
None,
+
&HashSet::default()
+
)?,
PagedAppendingCollection {
version: (1, 0),
items: vec![RecordId {
···
0,
)?;
}
-
let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, None, None)?;
+
let links =
+
storage.get_links("a.com", "app.t.c", ".abc.uri", 2, None, &HashSet::default())?;
let dids = storage.get_distinct_dids("a.com", "app.t.c", ".abc.uri", 2, None)?;
assert_eq!(
links,
···
next: Some(3),
}
);
-
let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, links.next, None)?;
+
let links = storage.get_links(
+
"a.com",
+
"app.t.c",
+
".abc.uri",
+
2,
+
links.next,
+
&HashSet::default(),
+
)?;
let dids = storage.get_distinct_dids("a.com", "app.t.c", ".abc.uri", 2, dids.next)?;
assert_eq!(
links,
···
next: Some(1),
}
);
-
let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, links.next, None)?;
+
let links = storage.get_links(
+
"a.com",
+
"app.t.c",
+
".abc.uri",
+
2,
+
links.next,
+
&HashSet::default(),
+
)?;
let dids = storage.get_distinct_dids("a.com", "app.t.c", ".abc.uri", 2, dids.next)?;
assert_eq!(
links,
···
".abc.uri",
2,
None,
-
Some(&HashSet::from([Did("did:plc:linker".to_string())])),
+
&HashSet::from([Did("did:plc:linker".to_string())]),
)?;
assert_eq!(
links,
···
".abc.uri",
2,
None,
-
Some(&HashSet::from([Did("did:plc:linker".to_string())])),
+
&HashSet::from([Did("did:plc:linker".to_string())]),
)?;
assert_eq!(
links,
···
".abc.uri",
2,
None,
-
Some(&HashSet::from([Did("did:plc:someone-else".to_string())])),
+
&HashSet::from([Did("did:plc:someone-else".to_string())]),
)?;
assert_eq!(
links,
···
".abc.uri",
2,
None,
-
Some(&HashSet::from([Did("did:plc:linker".to_string())])),
+
&HashSet::from([Did("did:plc:linker".to_string())]),
)?;
assert_eq!(
links,
···
".abc.uri",
2,
None,
-
Some(&HashSet::from([
+
&HashSet::from([
Did("did:plc:linker".to_string()),
Did("did:plc:someone-else".to_string()),
-
])),
+
]),
)?;
assert_eq!(
links,
···
".abc.uri",
2,
None,
-
Some(&HashSet::from([Did("did:plc:someone-unknown".to_string())])),
+
&HashSet::from([Did("did:plc:someone-unknown".to_string())]),
)?;
assert_eq!(
links,
···
0,
)?;
}
-
let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, None, None)?;
+
let links =
+
storage.get_links("a.com", "app.t.c", ".abc.uri", 2, None, &HashSet::default())?;
assert_eq!(
links,
PagedAppendingCollection {
···
next: Some(2),
}
);
-
let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, links.next, None)?;
+
let links = storage.get_links(
+
"a.com",
+
"app.t.c",
+
".abc.uri",
+
2,
+
links.next,
+
&HashSet::default(),
+
)?;
assert_eq!(
links,
PagedAppendingCollection {
···
0,
)?;
-
let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, None, None)?;
+
let links =
+
storage.get_links("a.com", "app.t.c", ".abc.uri", 2, None, &HashSet::default())?;
assert_eq!(
links,
PagedAppendingCollection {
···
},
0,
)?;
-
let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, links.next, None)?;
+
let links = storage.get_links(
+
"a.com",
+
"app.t.c",
+
".abc.uri",
+
2,
+
links.next,
+
&HashSet::default(),
+
)?;
assert_eq!(
links,
PagedAppendingCollection {
···
0,
)?;
-
let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, None, None)?;
+
let links =
+
storage.get_links("a.com", "app.t.c", ".abc.uri", 2, None, &HashSet::default())?;
assert_eq!(
links,
PagedAppendingCollection {
···
}),
0,
)?;
-
let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, links.next, None)?;
+
let links = storage.get_links(
+
"a.com",
+
"app.t.c",
+
".abc.uri",
+
2,
+
links.next,
+
&HashSet::default(),
+
)?;
assert_eq!(
links,
PagedAppendingCollection {
···
0,
)?;
-
let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, None, None)?;
+
let links =
+
storage.get_links("a.com", "app.t.c", ".abc.uri", 2, None, &HashSet::default())?;
assert_eq!(
links,
PagedAppendingCollection {
···
&ActionableEvent::DeactivateAccount("did:plc:asdf-1".into()),
0,
)?;
-
let links = storage.get_links("a.com", "app.t.c", ".abc.uri", 2, links.next, None)?;
+
let links = storage.get_links(
+
"a.com",
+
"app.t.c",
+
".abc.uri",
+
2,
+
links.next,
+
&HashSet::default(),
+
)?;
assert_eq!(
links,
PagedAppendingCollection {
+3 -3
constellation/src/storage/rocks_store.rs
···
path: &str,
limit: u64,
until: Option<u64>,
-
filter_dids: Option<&HashSet<Did>>,
+
filter_dids: &HashSet<Did>,
) -> Result<PagedAppendingCollection<RecordId>> {
let target_key = TargetKey(
Target(target.to_string()),
···
};
let mut linkers = self.get_target_linkers(&target_id)?;
-
if let Some(dids) = filter_dids {
+
if !filter_dids.is_empty() {
let mut did_filter = HashSet::new();
-
for did in dids {
+
for did in filter_dids {
let Some(DidIdValue(did_id, active)) =
self.did_id_table.get_id_val(&self.db, did)?
else {