Skip to content

Commit

Permalink
reduce logs
Browse files Browse the repository at this point in the history
  • Loading branch information
ragibkl committed Sep 12, 2024
1 parent e2c33e7 commit 11b53ee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/logs/query_logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct QueryLogs {

impl QueryLogs {
pub fn remove_expired_logs(&self) {
let query_time_cutoff = Utc::now() - Duration::minutes(10);
let query_time_cutoff = Utc::now() - Duration::minutes(2);

let mut logs_store_guard = self.logs_store.lock().unwrap();
for query_logs in logs_store_guard.values_mut() {
Expand Down
7 changes: 7 additions & 0 deletions src/logs/usage_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,18 @@ impl UsageStats {
pub fn merge_logs(&self, logs_hash_map: &HashMap<String, Vec<QueryLog>>) {
let mut last_query_times = self.last_query_times.lock().unwrap().clone();

let time_cutoff = Utc::now() - Duration::days(1);
last_query_times.retain(|_ip, qt| *qt > time_cutoff);

for (ip, queries) in logs_hash_map.iter() {
let Some(last_qt) = queries.last().map(|q| q.query_time) else {
continue;
};

if last_qt > time_cutoff {
continue;
}

match last_query_times.get_mut(ip) {
Some(qt) => *qt = last_qt,
None => {
Expand Down

0 comments on commit 11b53ee

Please sign in to comment.