@@ -507,11 +507,7 @@ impl FjallReader {
507507 merged. merge ( & counts) ;
508508 }
509509 }
510- out. push ( NsidCount {
511- nsid : nsid. to_string ( ) ,
512- creates : merged. counts ( ) . creates ,
513- dids_estimate : merged. dids ( ) . estimate ( ) as u64 ,
514- } ) ;
510+ out. push ( NsidCount :: new ( & nsid, & merged) ) ;
515511 }
516512
517513 let next_cursor = current_nsid. map ( |s| s. to_db_bytes ( ) ) . transpose ( ) ?;
@@ -617,11 +613,7 @@ impl FjallReader {
617613 . into_iter ( )
618614 . rev ( )
619615 . take ( limit)
620- . map ( |( nsid, cv) | NsidCount {
621- nsid : nsid. to_string ( ) ,
622- creates : cv. counts ( ) . creates ,
623- dids_estimate : cv. dids ( ) . estimate ( ) as u64 ,
624- } )
616+ . map ( |( nsid, cv) | NsidCount :: new ( & nsid, & cv) )
625617 . collect ( ) ;
626618 Ok ( counts)
627619 }
@@ -727,13 +719,13 @@ impl FjallReader {
727719 let mut prefix_count = CountsValue :: default ( ) ;
728720 #[ derive( Debug , Clone , PartialEq ) ]
729721 enum Child {
730- FullNsid ( String ) ,
722+ FullNsid ( Nsid ) ,
731723 ChildPrefix ( String ) ,
732724 }
733725 impl Child {
734726 fn from_prefix ( nsid : & Nsid , prefix : & NsidPrefix ) -> Option < Self > {
735727 if prefix. is_group_of ( nsid) {
736- return Some ( Child :: FullNsid ( nsid. to_string ( ) ) ) ;
728+ return Some ( Child :: FullNsid ( nsid. clone ( ) ) ) ;
737729 }
738730 let suffix = nsid. as_str ( ) . strip_prefix ( & format ! ( "{}." , prefix. 0 ) ) ?;
739731 let ( segment, _) = suffix. split_once ( '.' ) . unwrap ( ) ;
@@ -742,17 +734,17 @@ impl FjallReader {
742734 }
743735 fn is_before ( & self , other : & Child ) -> bool {
744736 match ( self , other) {
745- ( Child :: FullNsid ( s) , Child :: ChildPrefix ( o) ) if s == o => true ,
746- ( Child :: ChildPrefix ( s) , Child :: FullNsid ( o) ) if s == o => false ,
747- ( Child :: FullNsid ( s) , Child :: FullNsid ( o) ) => s < o,
737+ ( Child :: FullNsid ( s) , Child :: ChildPrefix ( o) ) if s. as_str ( ) == o => true ,
738+ ( Child :: ChildPrefix ( s) , Child :: FullNsid ( o) ) if s == o. as_str ( ) => false ,
739+ ( Child :: FullNsid ( s) , Child :: FullNsid ( o) ) => s. as_str ( ) < o. as_str ( ) ,
748740 ( Child :: ChildPrefix ( s) , Child :: ChildPrefix ( o) ) => s < o,
749- ( Child :: FullNsid ( s) , Child :: ChildPrefix ( o) ) => s < o,
750- ( Child :: ChildPrefix ( s) , Child :: FullNsid ( o) ) => s < o,
741+ ( Child :: FullNsid ( s) , Child :: ChildPrefix ( o) ) => s. to_string ( ) < * o,
742+ ( Child :: ChildPrefix ( s) , Child :: FullNsid ( o) ) => * s < o. to_string ( ) ,
751743 }
752744 }
753745 fn into_inner ( self ) -> String {
754746 match self {
755- Child :: FullNsid ( s) => s,
747+ Child :: FullNsid ( s) => s. to_string ( ) ,
756748 Child :: ChildPrefix ( s) => s,
757749 }
758750 }
@@ -791,16 +783,10 @@ impl FjallReader {
791783 }
792784 }
793785 items. push ( match child {
794- Child :: FullNsid ( nsid) => PrefixChild :: Collection ( NsidCount {
795- nsid,
796- creates : merged. counts ( ) . creates ,
797- dids_estimate : merged. dids ( ) . estimate ( ) as u64 ,
798- } ) ,
799- Child :: ChildPrefix ( prefix) => PrefixChild :: Prefix ( PrefixCount {
800- prefix,
801- creates : merged. counts ( ) . creates ,
802- dids_estimate : merged. dids ( ) . estimate ( ) as u64 ,
803- } ) ,
786+ Child :: FullNsid ( nsid) => PrefixChild :: Collection ( NsidCount :: new ( & nsid, & merged) ) ,
787+ Child :: ChildPrefix ( prefix) => {
788+ PrefixChild :: Prefix ( PrefixCount :: new ( & prefix, & merged) )
789+ }
804790 } ) ;
805791 }
806792
@@ -991,15 +977,11 @@ impl FjallReader {
991977 for kv in self . rollups . range ( ( start, end) ) {
992978 let ( key_bytes, val_bytes) = kv?;
993979 let key = db_complete :: < AllTimeRollupKey > ( & key_bytes) ?;
994- let nsid = key. collection ( ) . as_str ( ) . to_string ( ) ;
980+ let nsid = key. collection ( ) ;
995981 for term in & terms {
996982 if nsid. contains ( term) {
997983 let counts = db_complete :: < CountsValue > ( & val_bytes) ?;
998- matches. push ( NsidCount {
999- nsid : nsid. clone ( ) ,
1000- creates : counts. counts ( ) . creates ,
1001- dids_estimate : counts. dids ( ) . estimate ( ) as u64 ,
1002- } ) ;
984+ matches. push ( NsidCount :: new ( nsid, & counts) ) ;
1003985 break ;
1004986 }
1005987 }
@@ -2649,6 +2631,8 @@ mod tests {
26492631 vec![ PrefixChild :: Collection ( NsidCount {
26502632 nsid: "a.a.a" . to_string( ) ,
26512633 creates: 1 ,
2634+ updates: 0 ,
2635+ deletes: 0 ,
26522636 dids_estimate: 1
26532637 } ) , ]
26542638 ) ;
@@ -2695,7 +2679,9 @@ mod tests {
26952679 vec![ PrefixChild :: Prefix ( PrefixCount {
26962680 prefix: "a.a.a" . to_string( ) ,
26972681 creates: 1 ,
2698- dids_estimate: 1
2682+ updates: 0 ,
2683+ deletes: 0 ,
2684+ dids_estimate: 1 ,
26992685 } ) , ]
27002686 ) ;
27012687 assert_eq ! ( cursor, None ) ;
@@ -2750,6 +2736,8 @@ mod tests {
27502736 vec![ PrefixChild :: Prefix ( PrefixCount {
27512737 prefix: "a.a.a" . to_string( ) ,
27522738 creates: 2 ,
2739+ updates: 0 ,
2740+ deletes: 0 ,
27532741 dids_estimate: 1
27542742 } ) , ]
27552743 ) ;
@@ -2818,11 +2806,15 @@ mod tests {
28182806 PrefixChild :: Collection ( NsidCount {
28192807 nsid: "a.a.a.a" . to_string( ) ,
28202808 creates: 1 ,
2809+ updates: 0 ,
2810+ deletes: 0 ,
28212811 dids_estimate: 1
28222812 } ) ,
28232813 PrefixChild :: Prefix ( PrefixCount {
28242814 prefix: "a.a.a.a" . to_string( ) ,
28252815 creates: 1 ,
2816+ updates: 0 ,
2817+ deletes: 0 ,
28262818 dids_estimate: 1
28272819 } ) ,
28282820 ]
0 commit comments