From 33c7d40051838db721e1551556e91f2ad0d09530 Mon Sep 17 00:00:00 2001 From: peeech Date: Fri, 20 Oct 2023 09:19:18 +0200 Subject: [PATCH] add field dateCreated ini holoport_status for a TTL index --- src/db.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/db.rs b/src/db.rs index eef08ce..48e1c13 100644 --- a/src/db.rs +++ b/src/db.rs @@ -1,4 +1,4 @@ -use mongodb::bson::{self, doc, Document}; +use mongodb::bson::{self, doc, Document, DateTime}; use mongodb::options::AggregateOptions; use mongodb::{Client, Collection}; use rocket::futures::TryStreamExt; @@ -45,12 +45,12 @@ pub async fn ping_database(db: &Client) -> Result { } // Delete from host_statistics.holoport_status documents with -// timestamp field older than 30 days. Used for database cleanup +// timestamp field older than 14 days. Used for database cleanup pub async fn cleanup_database(db: &Client) -> Result { let hp_status: Collection = db.database("host_statistics").collection("holoport_status"); - let cutoff_ms = match get_cutoff_timestamp(30 * 24) { + let cutoff_ms = match get_cutoff_timestamp(14 * 24) { Some(x) => x, None => return Err(ApiError::BadRequest(HOURS_TOO_LARGE)), }; @@ -271,6 +271,7 @@ pub async fn add_holoport_status(hs: HostStats, db: &Client) -> Result<(), ApiEr "hposAppList": hpos_app_list, "channelVersion": hs.channel_version, "hposVersion": hs.hpos_version, + "dateCreated": DateTime::now(), // Field of bson type Date required for TTL index }; match hp_status.insert_one(val, None).await { Ok(_) => Ok(()),