MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / register

Method register

nodedb/src/engine/kv/sorted_index/manager.rs:75–102  ·  view source on GitHub ↗

Register a new sorted index. Returns the number of entries backfilled. `existing_entries` is an iterator of `(primary_key_bytes, value_bytes)` pairs from the KV hash table, used to populate the index from existing data.

(
        &mut self,
        tenant_id: u64,
        def: SortedIndexDef,
        existing_entries: impl Iterator<Item = (Vec<u8>, Vec<u8>)>,
    )

Source from the content-addressed store, hash-verified

73 /// `existing_entries` is an iterator of `(primary_key_bytes, value_bytes)` pairs
74 /// from the KV hash table, used to populate the index from existing data.
75 pub fn register(
76 &mut self,
77 tenant_id: u64,
78 def: SortedIndexDef,
79 existing_entries: impl Iterator<Item = (Vec<u8>, Vec<u8>)>,
80 ) -> u32 {
81 let idx_key = index_key(tenant_id, &def.name);
82 let tbl_key = super::super::engine_helpers::table_key(tenant_id, &def.collection);
83
84 let mut tree = OrderStatTree::new();
85 let mut backfilled = 0u32;
86
87 // Backfill from existing data.
88 for (pk_bytes, value_bytes) in existing_entries {
89 if let Some(sort_key) = extract_sort_key_from_value(&def, &value_bytes) {
90 tree.insert(sort_key, pk_bytes);
91 backfilled += 1;
92 }
93 }
94
95 self.collection_indexes
96 .entry(tbl_key)
97 .or_default()
98 .push(idx_key.clone());
99
100 self.indexes.insert(idx_key, SortedIndex { def, tree });
101 backfilled
102 }
103
104 /// Drop every sorted index belonging to `(tenant_id, collection)`.
105 /// Returns the number of indexes removed.

Callers 8

register_sorted_indexMethod · 0.45
register_and_backfillFunction · 0.45
rank_with_desc_scoreFunction · 0.45
top_kFunction · 0.45
on_put_updates_indexFunction · 0.45
drop_indexFunction · 0.45
score_lookupFunction · 0.45

Calls 7

table_keyFunction · 0.85
entryMethod · 0.80
index_keyFunction · 0.70
insertMethod · 0.45
pushMethod · 0.45
cloneMethod · 0.45

Tested by 7

register_and_backfillFunction · 0.36
rank_with_desc_scoreFunction · 0.36
top_kFunction · 0.36
on_put_updates_indexFunction · 0.36
drop_indexFunction · 0.36
score_lookupFunction · 0.36