diff --git a/constellation/src/server/mod.rs b/constellation/src/server/mod.rs index 09ca835..a77ab4b 100644 --- a/constellation/src/server/mod.rs +++ b/constellation/src/server/mod.rs @@ -239,9 +239,6 @@ struct GetManyToManyCountsQuery { /// Set the max number of links to return per page of results #[serde(default = "get_default_cursor_limit")] limit: u64, - /// Allow returning links in reverse order (default: false) - #[serde(default)] - reverse: bool, } #[derive(Serialize)] struct OtherSubjectCount { @@ -298,19 +295,12 @@ fn get_many_to_many_counts( let path_to_other = format!(".{}", query.path_to_other); - let order = if query.reverse { - Order::OldestToNewest - } else { - Order::NewestToOldest - }; - let paged = store .get_many_to_many_counts( &query.subject, collection, &path, &path_to_other, - order, limit, cursor_key, &filter_dids, @@ -527,9 +517,6 @@ struct GetLinkItemsQuery { from_dids: Option, // comma separated: gross #[serde(default = "get_default_cursor_limit")] limit: u64, - /// Allow returning links in reverse order (default: false) - #[serde(default)] - reverse: bool, } #[derive(Template, Serialize)] #[template(path = "links.html.j2")] @@ -578,18 +565,12 @@ fn get_links( } } - let order = if query.reverse { - Order::OldestToNewest - } else { - Order::NewestToOldest - }; - let paged = store .get_links( &query.target, &query.collection, &query.path, - order, + Order::NewestToOldest, limit, until, &filter_dids, @@ -622,6 +603,7 @@ struct GetDidItemsQuery { path: String, cursor: Option, limit: Option, + // TODO: allow reverse (er, forward) order as well } #[derive(Template, Serialize)] #[template(path = "dids.html.j2")] diff --git a/constellation/src/storage/mem_store.rs b/constellation/src/storage/mem_store.rs index 7915eeb..6e270fd 100644 --- a/constellation/src/storage/mem_store.rs +++ b/constellation/src/storage/mem_store.rs @@ -1,6 +1,5 @@ use super::{ - LinkReader, LinkStorage, Order, PagedAppendingCollection, PagedOrderedCollection, - StorageStats, + LinkReader, LinkStorage, Order, PagedAppendingCollection, PagedOrderedCollection, StorageStats, }; use crate::{ActionableEvent, CountsByCount, Did, RecordId}; use anyhow::Result; @@ -141,7 +140,6 @@ impl LinkReader for MemStorage { collection: &str, path: &str, path_to_other: &str, - order: Order, limit: u64, after: Option, filter_dids: &HashSet, @@ -159,10 +157,8 @@ impl LinkReader for MemStorage { let filter_to_targets: HashSet = HashSet::from_iter(filter_to_targets.iter().map(|s| Target::new(s))); - // the last type field here acts as an index to allow keeping track of the order in which - // we encountred single elements - let mut grouped_counts: HashMap, usize)> = HashMap::new(); - for (idx, (did, rkey)) in linkers.iter().flatten().cloned().enumerate() { + let mut grouped_counts: HashMap)> = HashMap::new(); + for (did, rkey) in linkers.iter().flatten().cloned() { if !filter_dids.is_empty() && !filter_dids.contains(&did) { continue; } @@ -188,23 +184,16 @@ impl LinkReader for MemStorage { .take(1) .next() { - let e = - grouped_counts - .entry(fwd_target.clone()) - .or_insert((0, HashSet::new(), idx)); + let e = grouped_counts.entry(fwd_target.clone()).or_default(); e.0 += 1; e.1.insert(did.clone()); } } let mut items: Vec<(String, u64, u64)> = grouped_counts .iter() - .map(|(k, (n, u, _))| (k.0.clone(), *n, u.len() as u64)) + .map(|(k, (n, u))| (k.0.clone(), *n, u.len() as u64)) .collect(); - // Sort based on order: OldestToNewest uses descending order, NewestToOldest uses ascending - match order { - Order::OldestToNewest => items.sort_by(|a, b| b.cmp(a)), - Order::NewestToOldest => items.sort(), - } + items.sort(); items = items .into_iter() .skip_while(|(t, _, _)| after.as_ref().map(|a| t <= a).unwrap_or(false)) diff --git a/constellation/src/storage/mod.rs b/constellation/src/storage/mod.rs index 77be8b9..68972de 100644 --- a/constellation/src/storage/mod.rs +++ b/constellation/src/storage/mod.rs @@ -81,7 +81,6 @@ pub trait LinkReader: Clone + Send + Sync + 'static { collection: &str, path: &str, path_to_other: &str, - order: Order, limit: u64, after: Option, filter_dids: &HashSet, @@ -1508,7 +1507,6 @@ mod tests { "a.b.c", ".d.e", ".f.g", - Order::NewestToOldest, 10, None, &HashSet::new(), @@ -1552,7 +1550,6 @@ mod tests { "app.t.c", ".abc.uri", ".def.uri", - Order::NewestToOldest, 10, None, &HashSet::new(), @@ -1652,7 +1649,6 @@ mod tests { "app.t.c", ".abc.uri", ".def.uri", - Order::NewestToOldest, 10, None, &HashSet::new(), @@ -1669,7 +1665,6 @@ mod tests { "app.t.c", ".abc.uri", ".def.uri", - Order::NewestToOldest, 10, None, &HashSet::from_iter([Did("did:plc:fdsa".to_string())]), @@ -1686,7 +1681,6 @@ mod tests { "app.t.c", ".abc.uri", ".def.uri", - Order::NewestToOldest, 10, None, &HashSet::new(), @@ -1698,104 +1692,4 @@ mod tests { } ); }); - - test_each_storage!(get_m2m_counts_reverse_order, |storage| { - // Create links from different DIDs to different targets - storage.push( - &ActionableEvent::CreateLinks { - record_id: RecordId { - did: "did:plc:user1".into(), - collection: "app.t.c".into(), - rkey: "post1".into(), - }, - links: vec![ - CollectedLink { - target: Link::Uri("a.com".into()), - path: ".abc.uri".into(), - }, - CollectedLink { - target: Link::Uri("b.com".into()), - path: ".def.uri".into(), - }, - ], - }, - 0, - )?; - storage.push( - &ActionableEvent::CreateLinks { - record_id: RecordId { - did: "did:plc:user2".into(), - collection: "app.t.c".into(), - rkey: "post1".into(), - }, - links: vec![ - CollectedLink { - target: Link::Uri("a.com".into()), - path: ".abc.uri".into(), - }, - CollectedLink { - target: Link::Uri("c.com".into()), - path: ".def.uri".into(), - }, - ], - }, - 1, - )?; - storage.push( - &ActionableEvent::CreateLinks { - record_id: RecordId { - did: "did:plc:user3".into(), - collection: "app.t.c".into(), - rkey: "post1".into(), - }, - links: vec![ - CollectedLink { - target: Link::Uri("a.com".into()), - path: ".abc.uri".into(), - }, - CollectedLink { - target: Link::Uri("d.com".into()), - path: ".def.uri".into(), - }, - ], - }, - 2, - )?; - - // Test NewestToOldest order (default order - by target ascending) - let counts = storage.get_many_to_many_counts( - "a.com", - "app.t.c", - ".abc.uri", - ".def.uri", - Order::NewestToOldest, - 10, - None, - &HashSet::new(), - &HashSet::new(), - )?; - assert_eq!(counts.items.len(), 3); - // Should be sorted by target in ascending order (alphabetical) - assert_eq!(counts.items[0].0, "b.com"); - assert_eq!(counts.items[1].0, "c.com"); - assert_eq!(counts.items[2].0, "d.com"); - - // Test OldestToNewest order (descending order - by target descending) - let counts = storage.get_many_to_many_counts( - "a.com", - "app.t.c", - ".abc.uri", - ".def.uri", - Order::OldestToNewest, - 10, - None, - &HashSet::new(), - &HashSet::new(), - )?; - assert_eq!(counts.items.len(), 3); - // Should be sorted by target in descending order (reverse alphabetical) - assert_eq!(counts.items[0].0, "d.com"); - assert_eq!(counts.items[1].0, "c.com"); - assert_eq!(counts.items[2].0, "b.com"); - }); } diff --git a/constellation/src/storage/rocks_store.rs b/constellation/src/storage/rocks_store.rs index 464f93b..0a5f7af 100644 --- a/constellation/src/storage/rocks_store.rs +++ b/constellation/src/storage/rocks_store.rs @@ -941,7 +941,6 @@ impl LinkReader for RocksStorage { collection: &str, path: &str, path_to_other: &str, - order: Order, limit: u64, after: Option, filter_dids: &HashSet, @@ -1072,7 +1071,6 @@ impl LinkReader for RocksStorage { } let mut items: Vec<(String, u64, u64)> = Vec::with_capacity(grouped_counts.len()); - for (target_id, (n, dids)) in &grouped_counts { let Some(target) = self .target_id_table @@ -1084,12 +1082,6 @@ impl LinkReader for RocksStorage { items.push((target.0 .0, *n, dids.len() as u64)); } - // Sort based on order: OldestToNewest uses descending order, NewestToOldest uses ascending - match order { - Order::OldestToNewest => items.sort_by(|a, b| b.cmp(a)), // descending - Order::NewestToOldest => items.sort(), // ascending - } - let next = if grouped_counts.len() as u64 >= limit { // yeah.... it's a number saved as a string......sorry grouped_counts diff --git a/constellation/templates/base.html.j2 b/constellation/templates/base.html.j2 index 3258d54..06928d5 100644 --- a/constellation/templates/base.html.j2 +++ b/constellation/templates/base.html.j2 @@ -40,10 +40,10 @@ padding: 0.5em 0.3em; max-width: 100%; } - pre.code input { - margin: 0; - padding: 0; - } + pre.code input { + margin: 0; + padding: 0; + } .stat { color: #f90; font-size: 1.618rem; diff --git a/constellation/templates/get-many-to-many-counts.html.j2 b/constellation/templates/get-many-to-many-counts.html.j2 index 849f6e1..b27815c 100644 --- a/constellation/templates/get-many-to-many-counts.html.j2 +++ b/constellation/templates/get-many-to-many-counts.html.j2 @@ -13,7 +13,6 @@ query.did, query.other_subject, query.limit, - query.reverse, ) %}

@@ -54,7 +53,6 @@ {% endfor %} - {% else %} diff --git a/constellation/templates/hello.html.j2 b/constellation/templates/hello.html.j2 index 99043ba..e9b95dc 100644 --- a/constellation/templates/hello.html.j2 +++ b/constellation/templates/hello.html.j2 @@ -70,7 +70,6 @@
  • did: optional, filter links to those from specific users. Include multiple times to filter by multiple users. Example: did=did:plc:vc7f4oafdgxsihk4cry2xpze&did=did:plc:vc7f4oafdgxsihk4cry2xpze

  • otherSubject: optional, filter secondary links to specific subjects. Include multiple times to filter by multiple users. Example: at://did:plc:vc7f4oafdgxsihk4cry2xpze/app.bsky.feed.post/3lgwdn7vd722r

  • limit: optional. Default: 16. Maximum: 100

  • -
  • reverse: optional, return links in reverse order. Default: false

  • Try it:

    @@ -81,7 +80,6 @@ [""], [""], 25, - false, ) %} @@ -104,7 +102,7 @@

    Try it:

    - {% call try_it::links("at://did:plc:a4pqq234yw7fqbddawjo7y35/app.bsky.feed.post/3m237ilwc372e", "app.bsky.feed.like", ".subject.uri", [""], 16, false) %} + {% call try_it::links("at://did:plc:a4pqq234yw7fqbddawjo7y35/app.bsky.feed.post/3m237ilwc372e", "app.bsky.feed.like", ".subject.uri", [""], 16) %}

    GET /links/distinct-dids

    diff --git a/constellation/templates/links.html.j2 b/constellation/templates/links.html.j2 index ba96905..24577db 100644 --- a/constellation/templates/links.html.j2 +++ b/constellation/templates/links.html.j2 @@ -6,7 +6,7 @@ {% block content %} - {% call try_it::links(query.target, query.collection, query.path, query.did, query.limit, query.reverse) %} + {% call try_it::links(query.target, query.collection, query.path, query.did, query.limit) %}

    Links to {{ query.target }} @@ -37,7 +37,6 @@ - {% else %} diff --git a/constellation/templates/try-it-macros.html.j2 b/constellation/templates/try-it-macros.html.j2 index a38831e..620aec9 100644 --- a/constellation/templates/try-it-macros.html.j2 +++ b/constellation/templates/try-it-macros.html.j2 @@ -25,7 +25,7 @@ {% endmacro %} -{% macro get_many_to_many_counts(subject, source, pathToOther, dids, otherSubjects, limit, reverse) %} +{% macro get_many_to_many_counts(subject, source, pathToOther, dids, otherSubjects, limit) %}
    GET /xrpc/blue.microcosm.links.getManyToManyCounts
       ?subject=      
    @@ -37,8 +37,7 @@
       {%- for otherSubject in otherSubjects %}{% if !otherSubject.is_empty() %}
       &otherSubject= {% endif %}{% endfor %}
                      
    -  &limit=        
    -  &reverse=      
    + &limit=
    {% endmacro %} -{% macro links(target, collection, path, dids, limit, reverse) %} +{% macro links(target, collection, path, dids, limit) %}
    GET /links
       ?target=     
    @@ -77,9 +76,7 @@
       {%- for did in dids %}{% if !did.is_empty() %}
       &did=        {% endif %}{% endfor %}
                    
    -  &limit=      
    -  &reverse=	   
    -  
    + &limit=