log documents added

This commit is contained in:
Tamo 2021-10-12 15:23:31 +02:00 committed by marin postma
parent 0b3e0a59cb
commit 1ed05c6c07
No known key found for this signature in database
GPG Key ID: 6088B7721C3E39F9
2 changed files with 22 additions and 6 deletions

View File

@ -8,9 +8,10 @@ use meilisearch_lib::milli::update::IndexDocumentsMethod;
use meilisearch_lib::MeiliSearch; use meilisearch_lib::MeiliSearch;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use serde::Deserialize; use serde::Deserialize;
use serde_json::Value; use serde_json::{json, Value};
use tokio::sync::mpsc; use tokio::sync::mpsc;
use crate::analytics::Analytics;
use crate::error::{MeilisearchHttpError, ResponseError}; use crate::error::{MeilisearchHttpError, ResponseError};
use crate::extractors::authentication::{policies::*, GuardedData}; use crate::extractors::authentication::{policies::*, GuardedData};
use crate::extractors::payload::Payload; use crate::extractors::payload::Payload;
@ -131,15 +132,29 @@ pub async fn add_documents(
params: web::Query<UpdateDocumentsQuery>, params: web::Query<UpdateDocumentsQuery>,
body: Payload, body: Payload,
req: HttpRequest, req: HttpRequest,
analytics: web::Data<&'static dyn Analytics>,
) -> Result<HttpResponse, ResponseError> { ) -> Result<HttpResponse, ResponseError> {
debug!("called with params: {:?}", params); debug!("called with params: {:?}", params);
document_addition( let content_type = req
req.headers() .headers()
.get("Content-type") .get("Content-type")
.map(|s| s.to_str().unwrap_or("unkown")), .map(|s| s.to_str().unwrap_or("unkown"));
let params = params.into_inner();
analytics.publish(
"Documents Added".to_string(),
json!({
"payload_type": content_type,
"with_primary_key": params.primary_key,
"index_creation": meilisearch.get_index(path.index_uid.clone()).await.is_ok(),
}),
);
document_addition(
content_type,
meilisearch, meilisearch,
path.into_inner().index_uid, path.index_uid.clone(),
params.into_inner().primary_key, params.primary_key,
body, body,
IndexDocumentsMethod::ReplaceDocuments, IndexDocumentsMethod::ReplaceDocuments,
) )

View File

@ -302,6 +302,7 @@ mod test {
impl_is_policy! {A B} impl_is_policy! {A B}
impl_is_policy! {A B C} impl_is_policy! {A B C}
impl_is_policy! {A B C D} impl_is_policy! {A B C D}
impl_is_policy! {A B C D E}
/// Emits a compile error if a route doesn't have the correct authentication policy. /// Emits a compile error if a route doesn't have the correct authentication policy.
/// ///