···
buckets: Vec<CursorBucket>,
) -> StorageResult<(JustCount, Vec<PrefixChild>, Option<Vec<u8>>)> {
668
-
let prefix_sub = String::sub_prefix(prefix.as_str())?;
668
+
// let prefix_sub_with_null = prefix.as_str().to_string().to_db_bytes()?;
669
+
let prefix_sub = String::sub_prefix(&prefix.terminated())?; // with trailing dot to ensure full segment match
let cursor_child = cursor
let decoded: String = db_complete(encoded_bytes)?;
673
-
let as_sub_prefix = String::sub_prefix(&decoded)?;
674
-
Ok::<_, EncodingError>(as_sub_prefix)
674
+
// TODO: write some tests for cursors, there's probably bugs here
675
+
let as_sub_prefix_with_null = decoded.to_db_bytes()?;
676
+
Ok::<_, EncodingError>(as_sub_prefix_with_null)
let mut iters: Vec<NsidCounter> = Vec::with_capacity(buckets.len());
···
let mut iters: Vec<_> = iters
712
-
it.map(|bla| bla.map(|(nsid, v)| (Child::from_prefix(&nsid, &prefix), v)))
715
+
bla.map(|(nsid, v)| {
716
+
let Some(child) = Child::from_prefix(&nsid, &prefix) else {
717
+
panic!("failed from_prefix: {nsid:?} {prefix:?} (bad iter bounds?)");
···
725
-
fn from_prefix(nsid: &Nsid, prefix: &NsidPrefix) -> Self {
734
+
fn from_prefix(nsid: &Nsid, prefix: &NsidPrefix) -> Option<Self> {
if prefix.is_group_of(nsid) {
727
-
Child::FullNsid(nsid.to_string())
731
-
.strip_prefix(&format!("{}.", prefix.0))
733
-
let (segment, _) = suffix.split_once('.').unwrap();
734
-
Child::ChildPrefix(format!("{}.{segment}", prefix.0))
736
+
return Some(Child::FullNsid(nsid.to_string()));
738
+
let suffix = nsid.as_str().strip_prefix(&format!("{}.", prefix.0))?;
739
+
let (segment, _) = suffix.split_once('.').unwrap();
740
+
let child_prefix = format!("{}.{segment}", prefix.0);
741
+
Some(Child::ChildPrefix(child_prefix))
fn is_before(&self, other: &Child) -> bool {
···
let (n, _) = write.step_rollup()?;
2477
+
fn get_prefix_children_lexi_empty() {
2478
+
let (read, _) = fjall_db();
2489
+
NsidPrefix::new("aaa.aaa").unwrap(),
2491
+
OrderCollectionsBy::Lexi { cursor: None },
2497
+
assert_eq!(creates, 0);
2498
+
assert_eq!(dids_estimate, 0);
2499
+
assert_eq!(children, vec![]);
2500
+
assert_eq!(cursor, None);
2504
+
fn get_prefix_excludes_exact_collection() -> anyhow::Result<()> {
2505
+
let (read, mut write) = fjall_db();
2507
+
let mut batch = TestBatch::default();
2509
+
"did:plc:person-a",
2517
+
write.insert_batch(batch.batch)?;
2518
+
write.step_rollup()?;
2528
+
) = read.get_prefix(
2529
+
NsidPrefix::new("a.a.a").unwrap(),
2531
+
OrderCollectionsBy::Lexi { cursor: None },
2535
+
assert_eq!(creates, 0);
2536
+
assert_eq!(dids_estimate, 0);
2537
+
assert_eq!(children, vec![]);
2538
+
assert_eq!(cursor, None);
2543
+
fn get_prefix_excludes_neighbour_collection() -> anyhow::Result<()> {
2544
+
let (read, mut write) = fjall_db();
2546
+
let mut batch = TestBatch::default();
2548
+
"did:plc:person-a",
2556
+
write.insert_batch(batch.batch)?;
2557
+
write.step_rollup()?;
2567
+
) = read.get_prefix(
2568
+
NsidPrefix::new("a.a.a").unwrap(),
2570
+
OrderCollectionsBy::Lexi { cursor: None },
2574
+
assert_eq!(creates, 0);
2575
+
assert_eq!(dids_estimate, 0);
2576
+
assert_eq!(children, vec![]);
2577
+
assert_eq!(cursor, None);
2582
+
fn get_prefix_includes_child_collection() -> anyhow::Result<()> {
2583
+
let (read, mut write) = fjall_db();
2585
+
let mut batch = TestBatch::default();
2587
+
"did:plc:person-a",
2595
+
write.insert_batch(batch.batch)?;
2596
+
write.step_rollup()?;
2606
+
) = read.get_prefix(
2607
+
NsidPrefix::new("a.a").unwrap(),
2609
+
OrderCollectionsBy::Lexi { cursor: None },
2613
+
assert_eq!(creates, 1);
2614
+
assert_eq!(dids_estimate, 1);
2617
+
vec![PrefixChild::Collection(NsidCount {
2618
+
nsid: "a.a.a".to_string(),
2623
+
assert_eq!(cursor, None);
2628
+
fn get_prefix_includes_child_prefix() -> anyhow::Result<()> {
2629
+
let (read, mut write) = fjall_db();
2631
+
let mut batch = TestBatch::default();
2633
+
"did:plc:person-a",
2641
+
write.insert_batch(batch.batch)?;
2642
+
write.step_rollup()?;
2652
+
) = read.get_prefix(
2653
+
NsidPrefix::new("a.a").unwrap(),
2655
+
OrderCollectionsBy::Lexi { cursor: None },
2659
+
assert_eq!(creates, 1);
2660
+
assert_eq!(dids_estimate, 1);
2663
+
vec![PrefixChild::Prefix(PrefixCount {
2664
+
prefix: "a.a.a".to_string(),
2669
+
assert_eq!(cursor, None);
2674
+
fn get_prefix_merges_child_prefixes() -> anyhow::Result<()> {
2675
+
let (read, mut write) = fjall_db();
2677
+
let mut batch = TestBatch::default();
2679
+
"did:plc:person-a",
2688
+
"did:plc:person-a",
2696
+
write.insert_batch(batch.batch)?;
2697
+
write.step_rollup()?;
2707
+
) = read.get_prefix(
2708
+
NsidPrefix::new("a.a").unwrap(),
2710
+
OrderCollectionsBy::Lexi { cursor: None },
2714
+
assert_eq!(creates, 2);
2715
+
assert_eq!(dids_estimate, 1);
2718
+
vec![PrefixChild::Prefix(PrefixCount {
2719
+
prefix: "a.a.a".to_string(),
2724
+
assert_eq!(cursor, None);
2729
+
fn get_prefix_exact_and_child_and_prefix() -> anyhow::Result<()> {
2730
+
let (read, mut write) = fjall_db();
2732
+
let mut batch = TestBatch::default();
2735
+
"did:plc:person-a",
2745
+
"did:plc:person-a",
2755
+
"did:plc:person-a",
2759
+
Some("rev-aaaaa"),
2763
+
write.insert_batch(batch.batch)?;
2764
+
write.step_rollup()?;
2774
+
) = read.get_prefix(
2775
+
NsidPrefix::new("a.a.a").unwrap(),
2777
+
OrderCollectionsBy::Lexi { cursor: None },
2781
+
assert_eq!(creates, 2);
2782
+
assert_eq!(dids_estimate, 1);
2786
+
PrefixChild::Collection(NsidCount {
2787
+
nsid: "a.a.a.a".to_string(),
2791
+
PrefixChild::Prefix(PrefixCount {
2792
+
prefix: "a.a.a.a".to_string(),
2798
+
assert_eq!(cursor, None);