mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-26 12:05:05 +08:00
methods to update index time metadata
This commit is contained in:
parent
c9f9d39b54
commit
80d0f9c49d
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -302,6 +302,7 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
"num-integer",
|
"num-integer",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
|
"serde",
|
||||||
"time",
|
"time",
|
||||||
"winapi 0.3.9",
|
"winapi 0.3.9",
|
||||||
]
|
]
|
||||||
@ -1277,6 +1278,7 @@ dependencies = [
|
|||||||
"anyhow",
|
"anyhow",
|
||||||
"bstr",
|
"bstr",
|
||||||
"byteorder",
|
"byteorder",
|
||||||
|
"chrono",
|
||||||
"criterion",
|
"criterion",
|
||||||
"crossbeam-channel",
|
"crossbeam-channel",
|
||||||
"csv",
|
"csv",
|
||||||
|
@ -8,6 +8,7 @@ edition = "2018"
|
|||||||
anyhow = "1.0.38"
|
anyhow = "1.0.38"
|
||||||
bstr = "0.2.15"
|
bstr = "0.2.15"
|
||||||
byteorder = "1.4.2"
|
byteorder = "1.4.2"
|
||||||
|
chrono = { version = "0.4.19", features = ["serde"] }
|
||||||
crossbeam-channel = "0.5.0"
|
crossbeam-channel = "0.5.0"
|
||||||
csv = "1.1.5"
|
csv = "1.1.5"
|
||||||
either = "1.6.1"
|
either = "1.6.1"
|
||||||
|
@ -6,6 +6,7 @@ use anyhow::Context;
|
|||||||
use heed::types::*;
|
use heed::types::*;
|
||||||
use heed::{PolyDatabase, Database, RwTxn, RoTxn};
|
use heed::{PolyDatabase, Database, RwTxn, RoTxn};
|
||||||
use roaring::RoaringBitmap;
|
use roaring::RoaringBitmap;
|
||||||
|
use chrono::{Utc, DateTime};
|
||||||
|
|
||||||
use crate::facet::FacetType;
|
use crate::facet::FacetType;
|
||||||
use crate::fields_ids_map::FieldsIdsMap;
|
use crate::fields_ids_map::FieldsIdsMap;
|
||||||
@ -28,6 +29,8 @@ pub const HARD_EXTERNAL_DOCUMENTS_IDS_KEY: &str = "hard-external-documents-ids";
|
|||||||
pub const SOFT_EXTERNAL_DOCUMENTS_IDS_KEY: &str = "soft-external-documents-ids";
|
pub const SOFT_EXTERNAL_DOCUMENTS_IDS_KEY: &str = "soft-external-documents-ids";
|
||||||
pub const WORDS_FST_KEY: &str = "words-fst";
|
pub const WORDS_FST_KEY: &str = "words-fst";
|
||||||
pub const WORDS_PREFIXES_FST_KEY: &str = "words-prefixes-fst";
|
pub const WORDS_PREFIXES_FST_KEY: &str = "words-prefixes-fst";
|
||||||
|
const CREATED_AT_KEY: &str = "created-at";
|
||||||
|
const UPDATED_AT_KEY: &str ="updated-at";
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Index {
|
pub struct Index {
|
||||||
@ -68,6 +71,17 @@ impl Index {
|
|||||||
let field_id_docid_facet_values = env.create_database(Some("field-id-docid-facet-values"))?;
|
let field_id_docid_facet_values = env.create_database(Some("field-id-docid-facet-values"))?;
|
||||||
let documents = env.create_database(Some("documents"))?;
|
let documents = env.create_database(Some("documents"))?;
|
||||||
|
|
||||||
|
{
|
||||||
|
let mut txn = env.write_txn()?;
|
||||||
|
// The db was just created, we update its metadata with the relevant information.
|
||||||
|
if main.get::<_, Str, SerdeJson<DateTime<Utc>>>(&txn, CREATED_AT_KEY)?.is_none() {
|
||||||
|
let now = Utc::now();
|
||||||
|
main.put::<_, Str, SerdeJson<DateTime<Utc>>>(&mut txn, UPDATED_AT_KEY, &now)?;
|
||||||
|
main.put::<_, Str, SerdeJson<DateTime<Utc>>>(&mut txn, CREATED_AT_KEY, &now)?;
|
||||||
|
txn.commit()?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(Index {
|
Ok(Index {
|
||||||
env,
|
env,
|
||||||
main,
|
main,
|
||||||
@ -393,4 +407,24 @@ impl Index {
|
|||||||
pub fn search<'a>(&'a self, rtxn: &'a RoTxn) -> Search<'a> {
|
pub fn search<'a>(&'a self, rtxn: &'a RoTxn) -> Search<'a> {
|
||||||
Search::new(rtxn, self)
|
Search::new(rtxn, self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the index creation time.
|
||||||
|
pub fn created_at(&self, rtxn: &RoTxn) -> heed::Result<DateTime<Utc>> {
|
||||||
|
let time = self.main
|
||||||
|
.get::<_, Str, SerdeJson<DateTime<Utc>>>(rtxn, CREATED_AT_KEY)?
|
||||||
|
.expect("Index without creation time");
|
||||||
|
Ok(time)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the index creation time.
|
||||||
|
pub fn updated_at(&self, rtxn: &RoTxn) -> heed::Result<DateTime<Utc>> {
|
||||||
|
let time = self.main
|
||||||
|
.get::<_, Str, SerdeJson<DateTime<Utc>>>(rtxn, UPDATED_AT_KEY)?
|
||||||
|
.expect("Index without update time");
|
||||||
|
Ok(time)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn set_updated_at(&self, wtxn: &mut RwTxn, time: &DateTime<Utc>) -> heed::Result<()> {
|
||||||
|
self.main.put::<_, Str, SerdeJson<DateTime<Utc>>>(wtxn, UPDATED_AT_KEY, &time)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user