mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-02 03:18:30 +02:00
Better compute aggragates
This commit is contained in:
parent
0bb7866f1e
commit
bf13268649
@ -5,8 +5,8 @@ use crate::routes::export::Export;
|
||||
pub struct ExportAnalytics {
|
||||
total_received: usize,
|
||||
has_api_key: bool,
|
||||
total_index_patterns: usize,
|
||||
total_patterns_with_filter: usize,
|
||||
sum_index_patterns: usize,
|
||||
sum_patterns_with_filter: usize,
|
||||
payload_sizes: Vec<u64>,
|
||||
}
|
||||
|
||||
@ -15,8 +15,8 @@ impl ExportAnalytics {
|
||||
let Export { url: _, api_key, payload_size, indexes } = export;
|
||||
|
||||
let has_api_key = api_key.is_some();
|
||||
let total_index_patterns = indexes.len();
|
||||
let total_patterns_with_filter =
|
||||
let index_patterns_count = indexes.len();
|
||||
let patterns_with_filter_count =
|
||||
indexes.values().filter(|settings| settings.filter.is_some()).count();
|
||||
let payload_sizes =
|
||||
if let Some(crate::routes::export::ByteWithDeserr(byte_size)) = payload_size {
|
||||
@ -28,8 +28,8 @@ impl ExportAnalytics {
|
||||
Self {
|
||||
total_received: 1,
|
||||
has_api_key,
|
||||
total_index_patterns,
|
||||
total_patterns_with_filter,
|
||||
sum_index_patterns: index_patterns_count,
|
||||
sum_patterns_with_filter: patterns_with_filter_count,
|
||||
payload_sizes,
|
||||
}
|
||||
}
|
||||
@ -43,8 +43,8 @@ impl Aggregate for ExportAnalytics {
|
||||
fn aggregate(mut self: Box<Self>, other: Box<Self>) -> Box<Self> {
|
||||
self.total_received += other.total_received;
|
||||
self.has_api_key |= other.has_api_key;
|
||||
self.total_index_patterns += other.total_index_patterns;
|
||||
self.total_patterns_with_filter += other.total_patterns_with_filter;
|
||||
self.sum_index_patterns += other.sum_index_patterns;
|
||||
self.sum_patterns_with_filter += other.sum_patterns_with_filter;
|
||||
self.payload_sizes.extend(other.payload_sizes);
|
||||
self
|
||||
}
|
||||
@ -56,11 +56,23 @@ impl Aggregate for ExportAnalytics {
|
||||
Some(self.payload_sizes.iter().sum::<u64>() / self.payload_sizes.len() as u64)
|
||||
};
|
||||
|
||||
let avg_index_patterns = if self.total_received == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(self.sum_index_patterns as f64 / self.total_received as f64)
|
||||
};
|
||||
|
||||
let avg_patterns_with_filter = if self.total_received == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(self.sum_patterns_with_filter as f64 / self.total_received as f64)
|
||||
};
|
||||
|
||||
serde_json::json!({
|
||||
"total_received": self.total_received,
|
||||
"has_api_key": self.has_api_key,
|
||||
"total_index_patterns": self.total_index_patterns,
|
||||
"total_patterns_with_filter": self.total_patterns_with_filter,
|
||||
"avg_index_patterns": avg_index_patterns,
|
||||
"avg_patterns_with_filter": avg_patterns_with_filter,
|
||||
"avg_payload_size": avg_payload_size,
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user