mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-26 12:05:05 +08:00
simplify the into_events methods
This commit is contained in:
parent
392ee86714
commit
a9523146a3
@ -153,28 +153,18 @@ mod segment {
|
||||
})
|
||||
.await;
|
||||
}
|
||||
println!("ANALYTICS: taking the lock on the search batcher");
|
||||
let get_search = std::mem::take(&mut *self.get_search_batcher.lock().await);
|
||||
let get_search = (get_search.total_received != 0).then(|| {
|
||||
get_search
|
||||
.into_event(self.user.clone(), "Document Searched GET".to_string())
|
||||
});
|
||||
let post_search = std::mem::take(&mut *self.post_search_batcher.lock().await);
|
||||
let post_search = (post_search.total_received != 0).then(|| {
|
||||
post_search
|
||||
.into_event(self.user.clone(), "Document Searched POST".to_string())
|
||||
});
|
||||
println!("ANALYTICS: taking the lock on the search batchers");
|
||||
let get_search = std::mem::take(&mut *self.get_search_batcher.lock().await)
|
||||
.into_event(&self.user, "Document Searched GET");
|
||||
let post_search = std::mem::take(&mut *self.post_search_batcher.lock().await)
|
||||
.into_event(&self.user, "Document Searched POST");
|
||||
println!("ANALYTICS: taking the lock on the documents batchers");
|
||||
let add_documents =
|
||||
std::mem::take(&mut *self.documents_added_batcher.lock().await);
|
||||
let add_documents = (add_documents.updated).then(|| {
|
||||
add_documents.into_event(self.user.clone(), "Documents Added".to_string())
|
||||
});
|
||||
std::mem::take(&mut *self.documents_added_batcher.lock().await)
|
||||
.into_event(&self.user, "Documents Added");
|
||||
let update_documents =
|
||||
std::mem::take(&mut *self.documents_updated_batcher.lock().await);
|
||||
let update_documents = (update_documents.updated).then(|| {
|
||||
update_documents
|
||||
.into_event(self.user.clone(), "Documents Updated".to_string())
|
||||
});
|
||||
std::mem::take(&mut *self.documents_updated_batcher.lock().await)
|
||||
.into_event(&self.user, "Documents Updated");
|
||||
// keep the lock on the batcher just for these three operations
|
||||
{
|
||||
println!("ANALYTICS: taking the lock on the batcher");
|
||||
@ -458,7 +448,10 @@ mod segment {
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn into_event(mut self, user: User, event_name: String) -> Track {
|
||||
pub fn into_event(mut self, user: &User, event_name: &str) -> Option<Track> {
|
||||
if self.total_received == 0 {
|
||||
None
|
||||
} else {
|
||||
let context = Some(json!({ "user-agent": self.user_agents}));
|
||||
let percentile_99th = 0.99 * (self.total_succeeded as f64 - 1.) + 1.;
|
||||
self.time_spent.drain(percentile_99th as usize..);
|
||||
@ -488,12 +481,13 @@ mod segment {
|
||||
},
|
||||
});
|
||||
|
||||
Track {
|
||||
user,
|
||||
event: event_name,
|
||||
Some(Track {
|
||||
user: user.clone(),
|
||||
event: event_name.to_string(),
|
||||
context,
|
||||
properties,
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -512,7 +506,10 @@ mod segment {
|
||||
}
|
||||
|
||||
impl DocumentsBatcher {
|
||||
pub fn into_event(mut self, user: User, event_name: String) -> Track {
|
||||
pub fn into_event(mut self, user: &User, event_name: &str) -> Option<Track> {
|
||||
if self.updated {
|
||||
None
|
||||
} else {
|
||||
let context = Some(json!({ "user-agent": self.user_agents}));
|
||||
|
||||
let properties = json!({
|
||||
@ -521,12 +518,13 @@ mod segment {
|
||||
"index_creation": self.index_creation,
|
||||
});
|
||||
|
||||
Track {
|
||||
user,
|
||||
event: event_name,
|
||||
Some(Track {
|
||||
user: user.clone(),
|
||||
event: event_name.to_string(),
|
||||
context,
|
||||
properties,
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user