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

Method register_sorted_index

nodedb/src/engine/kv/engine_sorted.rs:19–43  ·  view source on GitHub ↗

Register a new sorted index with backfill from existing KV data. Scans the hash table for all entries, extracts sort key columns, and populates the order-statistic tree. Returns backfill count.

(
        &mut self,
        tenant_id: u64,
        collection: &str,
        def: SortedIndexDef,
    )

Source from the content-addressed store, hash-verified

17 /// Scans the hash table for all entries, extracts sort key columns,
18 /// and populates the order-statistic tree. Returns backfill count.
19 pub fn register_sorted_index(
20 &mut self,
21 tenant_id: u64,
22 collection: &str,
23 def: SortedIndexDef,
24 ) -> u32 {
25 let tkey = table_key(tenant_id, collection);
26 let now_ms = super::current_ms();
27
28 // Collect existing entries from the hash table for backfill.
29 let entries: Vec<(Vec<u8>, Vec<u8>)> = self
30 .tables
31 .get(&tkey)
32 .map(|t| {
33 let (entries, _) = t.scan(0, usize::MAX, now_ms, None);
34 entries
35 .into_iter()
36 .map(|(k, v)| (k.to_vec(), v.to_vec()))
37 .collect()
38 })
39 .unwrap_or_default();
40
41 self.sorted_indexes
42 .register(tenant_id, def, entries.into_iter())
43 }
44
45 /// Drop a sorted index. Returns `true` if it existed.
46 pub fn drop_sorted_index(&mut self, tenant_id: u64, index_name: &str) -> bool {

Callers 1

Calls 7

table_keyFunction · 0.85
collectMethod · 0.80
current_msFunction · 0.70
getMethod · 0.45
scanMethod · 0.45
to_vecMethod · 0.45
registerMethod · 0.45

Tested by

no test coverage detected