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 once_cell::sync::Lazy;
use serde::Deserialize;
use serde_json::Value;
use serde_json::{json, Value};
use tokio::sync::mpsc;
use crate::analytics::Analytics;
use crate::error::{MeilisearchHttpError, ResponseError};
use crate::extractors::authentication::{policies::*, GuardedData};
use crate::extractors::payload::Payload;
@ -131,15 +132,29 @@ pub async fn add_documents(
params: web::Query<UpdateDocumentsQuery>,
body: Payload,
req: HttpRequest,
analytics: web::Data<&'static dyn Analytics>,
) -> Result<HttpResponse, ResponseError> {
debug!("called with params: {:?}", params);
document_addition(
req.headers()
let content_type = req
.headers()
.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,
path.into_inner().index_uid,
params.into_inner().primary_key,
path.index_uid.clone(),
params.primary_key,
body,
IndexDocumentsMethod::ReplaceDocuments,
)

View File

@ -302,6 +302,7 @@ mod test {
impl_is_policy! {A B}
impl_is_policy! {A B C}
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.
///