global: fixes

This commit is contained in:
nym21
2025-10-03 14:15:23 +02:00
parent cfdf8fdbca
commit d9c4653f82
9 changed files with 106 additions and 98 deletions
+3 -11
View File
@@ -228,25 +228,17 @@ impl<'a> Interface<'a> {
}
pub fn distinct_metric_count(&self) -> usize {
self.vecs.metric_count
self.vecs.distinct_metric_count
}
pub fn total_metric_count(&self) -> usize {
self.vecs.vec_count
self.vecs.total_metric_count
}
pub fn index_count(&self) -> usize {
self.vecs.index_count
}
pub fn get_indexes(&self) -> &[&'static str] {
pub fn get_indexes(&self) -> &BTreeMap<&'static str, &'static [&'static str]> {
&self.vecs.indexes
}
pub fn get_accepted_indexes(&self) -> &BTreeMap<&'static str, &'static [&'static str]> {
&self.vecs.accepted_indexes
}
pub fn get_metrics(&self, pagination: PaginationParam) -> &[&str] {
self.vecs.metrics(pagination)
}
+2 -2
View File
@@ -3,7 +3,7 @@ use std::fmt;
use derive_deref::Deref;
use schemars::JsonSchema;
use serde::Deserialize;
use sonic_rs::{JsonContainerTrait, JsonValueTrait, Value};
use serde_json::Value;
#[derive(Debug, Deref, JsonSchema)]
pub struct MaybeMetrics(Vec<String>);
@@ -46,7 +46,7 @@ impl<'de> Deserialize<'de> for MaybeMetrics {
} else if let Some(vec) = value.as_array() {
if vec.len() <= MAX_VECS {
Ok(MaybeMetrics(sanitize_metrics(
vec.into_iter().map(|s| s.as_str().unwrap().to_string()),
vec.iter().map(|s| s.as_str().unwrap().to_string()),
)))
} else {
Err(serde::de::Error::custom("Given parameter is too long"))
+5 -13
View File
@@ -14,11 +14,9 @@ pub struct Vecs<'a> {
pub metric_to_index_to_vec: BTreeMap<&'a str, IndexToVec<'a>>,
pub index_to_metric_to_vec: BTreeMap<Index, MetricToVec<'a>>,
pub metrics: Vec<&'a str>,
pub indexes: Vec<&'static str>,
pub accepted_indexes: BTreeMap<&'static str, &'static [&'static str]>,
pub index_count: usize,
pub metric_count: usize,
pub vec_count: usize,
pub indexes: BTreeMap<&'static str, &'static [&'static str]>,
pub distinct_metric_count: usize,
pub total_metric_count: usize,
metric_to_indexes: BTreeMap<&'a str, Vec<&'static str>>,
index_to_metrics: BTreeMap<Index, Vec<&'a str>>,
}
@@ -53,19 +51,13 @@ impl<'a> Vecs<'a> {
sort_ids(&mut ids);
this.metrics = ids;
this.metric_count = this.metric_to_index_to_vec.keys().count();
this.index_count = this.index_to_metric_to_vec.keys().count();
this.vec_count = this
this.distinct_metric_count = this.metric_to_index_to_vec.keys().count();
this.total_metric_count = this
.index_to_metric_to_vec
.values()
.map(|tree| tree.len())
.sum::<usize>();
this.indexes = this
.index_to_metric_to_vec
.keys()
.map(|i| i.serialize_long())
.collect::<Vec<_>>();
this.accepted_indexes = this
.index_to_metric_to_vec
.keys()
.map(|i| (i.serialize_long(), i.possible_values()))