diff --git a/constellation/src/lib.rs b/constellation/src/lib.rs index a2b4e98..bcb4e9b 100644 --- a/constellation/src/lib.rs +++ b/constellation/src/lib.rs @@ -22,7 +22,7 @@ pub enum ActionableEvent { DeleteAccount(Did), } -#[derive(Debug, Hash, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Debug, PartialEq, Eq, Hash, Clone, Serialize, Deserialize)] pub struct Did(pub String); impl> From for Did { @@ -31,7 +31,7 @@ impl> From for Did { } } -#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] pub struct RecordId { pub did: Did, pub collection: String, diff --git a/constellation/src/server/mod.rs b/constellation/src/server/mod.rs index 02c5e02..b04c281 100644 --- a/constellation/src/server/mod.rs +++ b/constellation/src/server/mod.rs @@ -709,7 +709,7 @@ struct GetManyToManyItemsQuery { #[serde(default = "get_default_cursor_limit")] limit: u64, } -#[derive(Debug, Serialize, Clone)] +#[derive(Debug, Serialize)] struct ManyToManyItem { link: RecordId, subject: String, diff --git a/constellation/src/storage/mem_store.rs b/constellation/src/storage/mem_store.rs index f2371d2..842ff6a 100644 --- a/constellation/src/storage/mem_store.rs +++ b/constellation/src/storage/mem_store.rs @@ -1,7 +1,7 @@ use super::{ - LinkReader, LinkStorage, Order, PagedAppendingCollection, PagedOrderedCollection, StorageStats, + LinkReader, LinkStorage, ManyToManyCursor, Order, PagedAppendingCollection, + PagedOrderedCollection, StorageStats, }; -use crate::storage::CompositeCursor; use crate::{ActionableEvent, CountsByCount, Did, RecordId}; use anyhow::{anyhow, Result}; @@ -264,9 +264,9 @@ impl LinkReader for MemStorage { let f = f .parse::() .map_err(|e| anyhow!("invalid cursor.1: {e}"))?; - Some(CompositeCursor { - backward: b, - forward: f, + Some(ManyToManyCursor { + backlink: b, + forward_link: f, }) } None => None, @@ -287,7 +287,7 @@ impl LinkReader for MemStorage { .iter() .enumerate() .filter_map(|(i, opt)| opt.as_ref().map(|v| (i, v))) - .skip_while(|(linker_idx, _)| cursor.is_some_and(|c| *linker_idx < c.backward as usize)) + .skip_while(|(linker_idx, _)| cursor.is_some_and(|c| *linker_idx < c.backlink as usize)) .filter(|(_, (did, _))| filter_dids.is_empty() || filter_dids.contains(did)) { let Some(links) = data.links.get(did).and_then(|m| { @@ -308,7 +308,7 @@ impl LinkReader for MemStorage { }) .skip_while(|(link_idx, _)| { cursor.is_some_and(|c| { - linker_idx == c.backward as usize && *link_idx <= c.forward as usize + linker_idx == c.backlink as usize && *link_idx <= c.forward_link as usize }) }) .take(limit as usize + 1 - items.len()) diff --git a/constellation/src/storage/mod.rs b/constellation/src/storage/mod.rs index 30a2185..51f0c6f 100644 --- a/constellation/src/storage/mod.rs +++ b/constellation/src/storage/mod.rs @@ -39,11 +39,10 @@ impl PagedAppendingCollection { } } -// get-many-to-many composite cursor #[derive(Copy, Clone, Debug)] -struct CompositeCursor { - backward: u64, - forward: u64, +struct ManyToManyCursor { + backlink: u64, + forward_link: u64, } /// A paged collection whose keys are sorted instead of indexed diff --git a/constellation/src/storage/rocks_store.rs b/constellation/src/storage/rocks_store.rs index 0b5f0ba..8b29289 100644 --- a/constellation/src/storage/rocks_store.rs +++ b/constellation/src/storage/rocks_store.rs @@ -1,8 +1,7 @@ use super::{ - ActionableEvent, LinkReader, LinkStorage, Order, PagedAppendingCollection, + ActionableEvent, LinkReader, LinkStorage, ManyToManyCursor, Order, PagedAppendingCollection, PagedOrderedCollection, StorageStats, }; -use crate::storage::CompositeCursor; use crate::{CountsByCount, Did, RecordId}; use anyhow::{anyhow, bail, Result}; @@ -1165,9 +1164,9 @@ impl LinkReader for RocksStorage { let f = f .parse::() .map_err(|e| anyhow!("invalid cursor.1: {e}"))?; - Some(CompositeCursor { - backward: b, - forward: f, + Some(ManyToManyCursor { + backlink: b, + forward_link: f, }) } None => None, @@ -1202,7 +1201,7 @@ impl LinkReader for RocksStorage { // iterate backwards (who linked to the target?) for (linker_idx, (did_id, rkey)) in linkers.0.iter().enumerate().skip_while(|(linker_idx, _)| { - cursor.is_some_and(|c| *linker_idx < c.backward as usize) + cursor.is_some_and(|c| *linker_idx < c.backlink as usize) }) { if did_id.is_empty() @@ -1233,7 +1232,7 @@ impl LinkReader for RocksStorage { }) .skip_while(|(link_idx, _)| { cursor.is_some_and(|c| { - linker_idx == c.backward as usize && *link_idx <= c.forward as usize + linker_idx == c.backlink as usize && *link_idx <= c.forward_link as usize }) }) .take(limit as usize + 1 - items.len())