From 48f7329a83961e25f9ef1e4d2f641d9954a81516 Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Wed, 31 Jul 2024 17:11:28 +0200 Subject: [PATCH 1/2] Specify index_mapper on `IndexStats` --- index-scheduler/src/index_mapper/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/index-scheduler/src/index_mapper/mod.rs b/index-scheduler/src/index_mapper/mod.rs index 14908120c..3cccb5a69 100644 --- a/index-scheduler/src/index_mapper/mod.rs +++ b/index-scheduler/src/index_mapper/mod.rs @@ -108,8 +108,10 @@ pub struct IndexStats { /// Association of every field name with the number of times it occurs in the documents. pub field_distribution: FieldDistribution, /// Creation date of the index. + #[serde(with = "time::serde::rfc3339")] pub created_at: OffsetDateTime, /// Date of the last update of the index. + #[serde(with = "time::serde::rfc3339")] pub updated_at: OffsetDateTime, } From 9ef710cad42b08d362e0a3dffd85558dcb8c3768 Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Wed, 31 Jul 2024 17:11:55 +0200 Subject: [PATCH 2/2] Use wrapper that forces the desired date format --- milli/src/index.rs | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/milli/src/index.rs b/milli/src/index.rs index 3a2f3169c..512e911aa 100644 --- a/milli/src/index.rs +++ b/milli/src/index.rs @@ -9,7 +9,6 @@ use heed::{CompactionOption, Database, RoTxn, RwTxn, Unspecified}; use roaring::RoaringBitmap; use rstar::RTree; use serde::{Deserialize, Serialize}; -use time::OffsetDateTime; use crate::documents::PrimaryKey; use crate::error::{InternalError, UserError}; @@ -173,8 +172,8 @@ impl Index { pub fn new_with_creation_dates>( mut options: heed::EnvOpenOptions, path: P, - created_at: OffsetDateTime, - updated_at: OffsetDateTime, + created_at: time::OffsetDateTime, + updated_at: time::OffsetDateTime, ) -> Result { use db_name::*; @@ -256,22 +255,22 @@ impl Index { } pub fn new>(options: heed::EnvOpenOptions, path: P) -> Result { - let now = OffsetDateTime::now_utc(); + let now = time::OffsetDateTime::now_utc(); Self::new_with_creation_dates(options, path, now, now) } fn set_creation_dates( env: &heed::Env, main: Database, - created_at: OffsetDateTime, - updated_at: OffsetDateTime, + created_at: time::OffsetDateTime, + updated_at: time::OffsetDateTime, ) -> heed::Result<()> { let mut txn = env.write_txn()?; // The db was just created, we update its metadata with the relevant information. let main = main.remap_types::>(); if main.get(&txn, main_key::CREATED_AT_KEY)?.is_none() { - main.put(&mut txn, main_key::UPDATED_AT_KEY, &updated_at)?; - main.put(&mut txn, main_key::CREATED_AT_KEY, &created_at)?; + main.put(&mut txn, main_key::UPDATED_AT_KEY, &OffsetDateTime(updated_at))?; + main.put(&mut txn, main_key::CREATED_AT_KEY, &OffsetDateTime(created_at))?; txn.commit()?; } Ok(()) @@ -371,7 +370,7 @@ impl Index { wtxn: &mut RwTxn<'_>, primary_key: &str, ) -> heed::Result<()> { - self.set_updated_at(wtxn, &OffsetDateTime::now_utc())?; + self.set_updated_at(wtxn, &time::OffsetDateTime::now_utc())?; self.main.remap_types::().put(wtxn, main_key::PRIMARY_KEY_KEY, primary_key) } @@ -1323,7 +1322,7 @@ impl Index { } /// Returns the index creation time. - pub fn created_at(&self, rtxn: &RoTxn<'_>) -> Result { + pub fn created_at(&self, rtxn: &RoTxn<'_>) -> Result { Ok(self .main .remap_types::>() @@ -1331,11 +1330,12 @@ impl Index { .ok_or(InternalError::DatabaseMissingEntry { db_name: db_name::MAIN, key: Some(main_key::CREATED_AT_KEY), - })?) + })? + .0) } /// Returns the index last updated time. - pub fn updated_at(&self, rtxn: &RoTxn<'_>) -> Result { + pub fn updated_at(&self, rtxn: &RoTxn<'_>) -> Result { Ok(self .main .remap_types::>() @@ -1343,18 +1343,19 @@ impl Index { .ok_or(InternalError::DatabaseMissingEntry { db_name: db_name::MAIN, key: Some(main_key::UPDATED_AT_KEY), - })?) + })? + .0) } pub(crate) fn set_updated_at( &self, wtxn: &mut RwTxn<'_>, - time: &OffsetDateTime, + time: &time::OffsetDateTime, ) -> heed::Result<()> { self.main.remap_types::>().put( wtxn, main_key::UPDATED_AT_KEY, - time, + &OffsetDateTime(*time), ) } @@ -1681,6 +1682,10 @@ pub struct IndexEmbeddingConfig { pub user_provided: RoaringBitmap, } +#[derive(Serialize, Deserialize)] +#[serde(transparent)] +struct OffsetDateTime(#[serde(with = "time::serde::rfc3339")] time::OffsetDateTime); + #[cfg(test)] pub(crate) mod tests { use std::collections::HashSet;