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

Function aggregate_cache_key

nodedb/src/data/executor/handlers/aggregate.rs:28–71  ·  view source on GitHub ↗
(
    tid: u64,
    collection: &str,
    group_by: &[String],
    aggregates: &[AggregateSpec],
    sub_group_by: &[String],
    sub_aggregates: &[AggregateSpec],
)

Source from the content-addressed store, hash-verified

26// ── Cache key ──────────────────────────────────────────────────────────────
27
28fn aggregate_cache_key(
29 tid: u64,
30 collection: &str,
31 group_by: &[String],
32 aggregates: &[AggregateSpec],
33 sub_group_by: &[String],
34 sub_aggregates: &[AggregateSpec],
35) -> (crate::types::TenantId, String) {
36 use std::fmt::Write;
37 let mut rest = format!(
38 "{collection}\0{}\0{}",
39 group_by.join(","),
40 aggregates
41 .iter()
42 .map(|agg| {
43 if agg.expr.is_some() {
44 format!("{}(expr)->{}", agg.function, agg.alias)
45 } else {
46 format!("{}({})->{}", agg.function, agg.field, agg.alias)
47 }
48 })
49 .collect::<Vec<_>>()
50 .join(",")
51 );
52 if !sub_group_by.is_empty() || !sub_aggregates.is_empty() {
53 let _ = write!(
54 rest,
55 "\0sub:{}\0{}",
56 sub_group_by.join(","),
57 sub_aggregates
58 .iter()
59 .map(|agg| {
60 if agg.expr.is_some() {
61 format!("{}(expr)->{}", agg.function, agg.alias)
62 } else {
63 format!("{}({})->{}", agg.function, agg.field, agg.alias)
64 }
65 })
66 .collect::<Vec<_>>()
67 .join(",")
68 );
69 }
70 (crate::types::TenantId::new(tid), rest)
71}
72
73fn legacy_aggregate_pairs(aggregates: &[AggregateSpec]) -> Option<Vec<(String, String)>> {
74 aggregates

Callers 1

execute_aggregateMethod · 0.85

Calls 1

is_emptyMethod · 0.45

Tested by

no test coverage detected