diff --git a/milli/Cargo.toml b/milli/Cargo.toml index 63d0785cb..7957058f8 100644 --- a/milli/Cargo.toml +++ b/milli/Cargo.toml @@ -9,7 +9,6 @@ bimap = { version = "0.6.1", features = ["serde"] } bincode = "1.3.3" bstr = "0.2.15" byteorder = "1.4.2" -chrono = { version = "0.4.19", features = ["serde"] } concat-arrays = "0.1.2" crossbeam-channel = "0.5.1" either = "1.6.1" @@ -36,6 +35,7 @@ slice-group-by = "0.2.6" smallstr = { version = "0.2.0", features = ["serde"] } smallvec = "1.6.1" tempfile = "3.2.0" +time = { version = "0.3.7", features = ["serde-well-known", "formatting", "parsing", "macros"] } uuid = { version = "0.8.2", features = ["v4"] } filter-parser = { path = "../filter-parser" } diff --git a/milli/src/index.rs b/milli/src/index.rs index 70081dfb0..568d50ad8 100644 --- a/milli/src/index.rs +++ b/milli/src/index.rs @@ -3,12 +3,12 @@ use std::collections::{HashMap, HashSet}; use std::mem::size_of; use std::path::Path; -use chrono::{DateTime, Utc}; use heed::flags::Flags; use heed::types::*; use heed::{Database, PolyDatabase, RoTxn, RwTxn}; use roaring::RoaringBitmap; use rstar::RTree; +use time::OffsetDateTime; use crate::error::{InternalError, UserError}; use crate::fields_ids_map::FieldsIdsMap; @@ -156,10 +156,19 @@ impl Index { fn initialize_creation_dates(env: &heed::Env, main: PolyDatabase) -> heed::Result<()> { let mut txn = env.write_txn()?; // The db was just created, we update its metadata with the relevant information. - if main.get::<_, Str, SerdeJson>>(&txn, main_key::CREATED_AT_KEY)?.is_none() { - let now = Utc::now(); - main.put::<_, Str, SerdeJson>>(&mut txn, main_key::UPDATED_AT_KEY, &now)?; - main.put::<_, Str, SerdeJson>>(&mut txn, main_key::CREATED_AT_KEY, &now)?; + if main.get::<_, Str, SerdeJson>(&txn, main_key::CREATED_AT_KEY)?.is_none() + { + let now = OffsetDateTime::now_utc(); + main.put::<_, Str, SerdeJson>( + &mut txn, + main_key::UPDATED_AT_KEY, + &now, + )?; + main.put::<_, Str, SerdeJson>( + &mut txn, + main_key::CREATED_AT_KEY, + &now, + )?; txn.commit()?; } Ok(()) @@ -219,7 +228,7 @@ impl Index { /// Writes the documents primary key, this is the field name that is used to store the id. pub(crate) fn put_primary_key(&self, wtxn: &mut RwTxn, primary_key: &str) -> heed::Result<()> { - self.set_updated_at(wtxn, &Utc::now())?; + self.set_updated_at(wtxn, &OffsetDateTime::now_utc())?; self.main.put::<_, Str, Str>(wtxn, main_key::PRIMARY_KEY_KEY, &primary_key) } @@ -829,10 +838,10 @@ 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 - .get::<_, Str, SerdeJson>>(rtxn, main_key::CREATED_AT_KEY)? + .get::<_, Str, SerdeJson>(rtxn, main_key::CREATED_AT_KEY)? .ok_or(InternalError::DatabaseMissingEntry { db_name: db_name::MAIN, key: Some(main_key::CREATED_AT_KEY), @@ -840,10 +849,10 @@ impl Index { } /// 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 - .get::<_, Str, SerdeJson>>(rtxn, main_key::UPDATED_AT_KEY)? + .get::<_, Str, SerdeJson>(rtxn, main_key::UPDATED_AT_KEY)? .ok_or(InternalError::DatabaseMissingEntry { db_name: db_name::MAIN, key: Some(main_key::UPDATED_AT_KEY), @@ -853,9 +862,9 @@ impl Index { pub(crate) fn set_updated_at( &self, wtxn: &mut RwTxn, - time: &DateTime, + time: &OffsetDateTime, ) -> heed::Result<()> { - self.main.put::<_, Str, SerdeJson>>(wtxn, main_key::UPDATED_AT_KEY, &time) + self.main.put::<_, Str, SerdeJson>(wtxn, main_key::UPDATED_AT_KEY, &time) } } diff --git a/milli/src/update/clear_documents.rs b/milli/src/update/clear_documents.rs index 8c9178d4e..644547b91 100644 --- a/milli/src/update/clear_documents.rs +++ b/milli/src/update/clear_documents.rs @@ -1,5 +1,5 @@ -use chrono::Utc; use roaring::RoaringBitmap; +use time::OffsetDateTime; use crate::{ExternalDocumentsIds, FieldDistribution, Index, Result}; @@ -14,7 +14,7 @@ impl<'t, 'u, 'i> ClearDocuments<'t, 'u, 'i> { } pub fn execute(self) -> Result { - self.index.set_updated_at(self.wtxn, &Utc::now())?; + self.index.set_updated_at(self.wtxn, &OffsetDateTime::now_utc())?; let Index { env: _env, main: _main, diff --git a/milli/src/update/delete_documents.rs b/milli/src/update/delete_documents.rs index 19f1d9f42..2391bd0e4 100644 --- a/milli/src/update/delete_documents.rs +++ b/milli/src/update/delete_documents.rs @@ -1,13 +1,13 @@ use std::collections::btree_map::Entry; use std::collections::HashMap; -use chrono::Utc; use fst::IntoStreamer; use heed::types::ByteSlice; use heed::{BytesDecode, BytesEncode}; use roaring::RoaringBitmap; use serde::{Deserialize, Serialize}; use serde_json::Value; +use time::OffsetDateTime; use super::ClearDocuments; use crate::error::{InternalError, SerializationError, UserError}; @@ -61,7 +61,7 @@ impl<'t, 'u, 'i> DeleteDocuments<'t, 'u, 'i> { } pub fn execute(self) -> Result { - self.index.set_updated_at(self.wtxn, &Utc::now())?; + self.index.set_updated_at(self.wtxn, &OffsetDateTime::now_utc())?; // We retrieve the current documents ids that are in the database. let mut documents_ids = self.index.documents_ids(self.wtxn)?; let current_documents_ids_len = documents_ids.len(); diff --git a/milli/src/update/facets.rs b/milli/src/update/facets.rs index a2f17cba3..83a3d2267 100644 --- a/milli/src/update/facets.rs +++ b/milli/src/update/facets.rs @@ -2,12 +2,12 @@ use std::fs::File; use std::num::{NonZeroU8, NonZeroUsize}; use std::{cmp, mem}; -use chrono::Utc; use grenad::{CompressionType, Reader, Writer}; use heed::types::{ByteSlice, DecodeIgnore}; use heed::{BytesEncode, Error}; use log::debug; use roaring::RoaringBitmap; +use time::OffsetDateTime; use crate::error::InternalError; use crate::heed_codec::facet::{ @@ -53,7 +53,7 @@ impl<'t, 'u, 'i> Facets<'t, 'u, 'i> { #[logging_timer::time("Facets::{}")] pub fn execute(self) -> Result<()> { - self.index.set_updated_at(self.wtxn, &Utc::now())?; + self.index.set_updated_at(self.wtxn, &OffsetDateTime::now_utc())?; // We get the faceted fields to be able to create the facet levels. let faceted_fields = self.index.faceted_fields_ids(self.wtxn)?; diff --git a/milli/src/update/settings.rs b/milli/src/update/settings.rs index 91ef187f5..c413f81c3 100644 --- a/milli/src/update/settings.rs +++ b/milli/src/update/settings.rs @@ -1,10 +1,10 @@ use std::collections::{BTreeSet, HashMap, HashSet}; use std::result::Result as StdResult; -use chrono::Utc; use itertools::Itertools; use meilisearch_tokenizer::{Analyzer, AnalyzerConfig}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; +use time::OffsetDateTime; use super::index_documents::{IndexDocumentsConfig, Transform}; use super::IndexerConfig; @@ -454,7 +454,7 @@ impl<'a, 't, 'u, 'i> Settings<'a, 't, 'u, 'i> { where F: Fn(UpdateIndexingStep) + Sync, { - self.index.set_updated_at(self.wtxn, &Utc::now())?; + self.index.set_updated_at(self.wtxn, &OffsetDateTime::now_utc())?; let old_faceted_fields = self.index.faceted_fields(&self.wtxn)?; let old_fields_ids_map = self.index.fields_ids_map(&self.wtxn)?;