MeiliSearch/meilisearch-http/src/analytics/mock_analytics.rs

59 lines
1.5 KiB
Rust
Raw Normal View History

use std::{any::Any, sync::Arc};
2021-10-27 18:16:13 +02:00
use actix_web::HttpRequest;
2022-10-13 15:02:59 +02:00
use meilisearch_types::InstanceUid;
2021-10-27 18:16:13 +02:00
use serde_json::Value;
use crate::{routes::indexes::documents::UpdateDocumentsQuery, Opt};
use super::{find_user_id, Analytics};
2022-10-13 15:02:59 +02:00
pub struct MockAnalytics {
instance_uid: Option<InstanceUid>,
}
2021-10-27 18:16:13 +02:00
2021-10-28 16:28:41 +02:00
#[derive(Default)]
2022-10-13 15:02:59 +02:00
pub struct SearchAggregator;
2021-10-28 16:28:41 +02:00
#[allow(dead_code)]
impl SearchAggregator {
pub fn from_query(_: &dyn Any, _: &dyn Any) -> Self {
Self::default()
}
pub fn succeed(&mut self, _: &dyn Any) {}
2021-10-28 16:28:41 +02:00
}
2021-10-27 18:16:13 +02:00
impl MockAnalytics {
2021-10-29 16:10:58 +02:00
#[allow(clippy::new_ret_no_self)]
2022-10-13 15:02:59 +02:00
pub fn new(opt: &Opt) -> Arc<dyn Analytics> {
let instance_uid = find_user_id(&opt.db_path);
Arc::new(Self { instance_uid })
2021-10-27 18:16:13 +02:00
}
}
impl Analytics for MockAnalytics {
2022-10-13 15:02:59 +02:00
fn instance_uid(&self) -> Option<&meilisearch_types::InstanceUid> {
self.instance_uid.as_ref()
}
2021-10-27 18:16:13 +02:00
// These methods are noop and should be optimized out
fn publish(&self, _event_name: String, _send: Value, _request: Option<&HttpRequest>) {}
fn get_search(&self, _aggregate: super::SearchAggregator) {}
fn post_search(&self, _aggregate: super::SearchAggregator) {}
2021-10-27 18:16:13 +02:00
fn add_documents(
&self,
2021-10-27 18:16:13 +02:00
_documents_query: &UpdateDocumentsQuery,
_index_creation: bool,
_request: &HttpRequest,
) {
}
fn update_documents(
&self,
2021-10-27 18:16:13 +02:00
_documents_query: &UpdateDocumentsQuery,
_index_creation: bool,
_request: &HttpRequest,
) {
}
}