mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 14:54:27 +01:00
Combine created and added into date
This commit is contained in:
parent
d3eb8d2d5c
commit
5a0a0468df
@ -788,7 +788,7 @@ impl IndexScheduler {
|
|||||||
let index = if must_create_index {
|
let index = if must_create_index {
|
||||||
// create the index if it doesn't already exist
|
// create the index if it doesn't already exist
|
||||||
let wtxn = self.env.write_txn()?;
|
let wtxn = self.env.write_txn()?;
|
||||||
self.index_mapper.create_index(wtxn, index_uid, None, None)?
|
self.index_mapper.create_index(wtxn, index_uid, None)?
|
||||||
} else {
|
} else {
|
||||||
let rtxn = self.env.read_txn()?;
|
let rtxn = self.env.read_txn()?;
|
||||||
self.index_mapper.index(&rtxn, index_uid)?
|
self.index_mapper.index(&rtxn, index_uid)?
|
||||||
@ -805,7 +805,7 @@ impl IndexScheduler {
|
|||||||
if self.index_mapper.exists(&wtxn, &index_uid)? {
|
if self.index_mapper.exists(&wtxn, &index_uid)? {
|
||||||
return Err(Error::IndexAlreadyExists(index_uid));
|
return Err(Error::IndexAlreadyExists(index_uid));
|
||||||
}
|
}
|
||||||
self.index_mapper.create_index(wtxn, &index_uid, None, None)?;
|
self.index_mapper.create_index(wtxn, &index_uid, None)?;
|
||||||
|
|
||||||
self.process_batch(Batch::IndexUpdate { index_uid, primary_key, task })
|
self.process_batch(Batch::IndexUpdate { index_uid, primary_key, task })
|
||||||
}
|
}
|
||||||
|
@ -66,30 +66,18 @@ impl IndexMapper {
|
|||||||
|
|
||||||
/// Create or open an index in the specified path.
|
/// Create or open an index in the specified path.
|
||||||
/// The path *must* exists or an error will be thrown.
|
/// The path *must* exists or an error will be thrown.
|
||||||
fn create_or_open_index(&self, path: &Path, created: Option<time::OffsetDateTime>, updated: Option<time::OffsetDateTime>) -> Result<Index> {
|
fn create_or_open_index(&self, path: &Path, date: Option<(time::OffsetDateTime, time::OffsetDateTime)>) -> Result<Index> {
|
||||||
let mut options = EnvOpenOptions::new();
|
let mut options = EnvOpenOptions::new();
|
||||||
options.map_size(clamp_to_page_size(self.index_size));
|
options.map_size(clamp_to_page_size(self.index_size));
|
||||||
options.max_readers(1024);
|
options.max_readers(1024);
|
||||||
|
|
||||||
let created_at;
|
let (created, updated) = date.unwrap();
|
||||||
if created == None {
|
|
||||||
created_at = time::OffsetDateTime::now_utc();
|
|
||||||
} else {
|
|
||||||
created_at = created.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
let updated_at;
|
Ok(Index::new_with_creation_dates(options, path, created, updated)?)
|
||||||
if updated == None {
|
|
||||||
updated_at = time::OffsetDateTime::now_utc();
|
|
||||||
} else {
|
|
||||||
updated_at = updated.unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(Index::new_with_creation_dates(options, path, created_at, updated_at)?)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get or create the index.
|
/// Get or create the index.
|
||||||
pub fn create_index(&self, mut wtxn: RwTxn, name: &str, created_at: Option<time::OffsetDateTime>, updated_at: Option<time::OffsetDateTime>) -> Result<Index> {
|
pub fn create_index(&self, mut wtxn: RwTxn, name: &str, date: Option<(time::OffsetDateTime, time::OffsetDateTime)>) -> Result<Index> {
|
||||||
match self.index(&wtxn, name) {
|
match self.index(&wtxn, name) {
|
||||||
Ok(index) => {
|
Ok(index) => {
|
||||||
wtxn.commit()?;
|
wtxn.commit()?;
|
||||||
@ -102,9 +90,7 @@ impl IndexMapper {
|
|||||||
let index_path = self.base_path.join(uuid.to_string());
|
let index_path = self.base_path.join(uuid.to_string());
|
||||||
fs::create_dir_all(&index_path)?;
|
fs::create_dir_all(&index_path)?;
|
||||||
|
|
||||||
//let created_at = Some(time::OffsetDateTime::now_utc());
|
let index = self.create_or_open_index(&index_path, date)?;
|
||||||
//let updated_at = Some(time::OffsetDateTime::now_utc());
|
|
||||||
let index = self.create_or_open_index(&index_path, created_at, updated_at)?;
|
|
||||||
|
|
||||||
wtxn.commit()?;
|
wtxn.commit()?;
|
||||||
// TODO: it would be better to lazily create the index. But we need an Index::open function for milli.
|
// TODO: it would be better to lazily create the index. But we need an Index::open function for milli.
|
||||||
@ -198,9 +184,8 @@ impl IndexMapper {
|
|||||||
Entry::Vacant(entry) => {
|
Entry::Vacant(entry) => {
|
||||||
let index_path = self.base_path.join(uuid.to_string());
|
let index_path = self.base_path.join(uuid.to_string());
|
||||||
|
|
||||||
let created_at = Some(time::OffsetDateTime::now_utc());
|
let date = Some(( time::OffsetDateTime::now_utc(), time::OffsetDateTime::now_utc() ));
|
||||||
let updated_at = Some(time::OffsetDateTime::now_utc());
|
let index = self.create_or_open_index(&index_path, date)?;
|
||||||
let index = self.create_or_open_index(&index_path, created_at, updated_at)?;
|
|
||||||
entry.insert(Available(index.clone()));
|
entry.insert(Available(index.clone()));
|
||||||
index
|
index
|
||||||
}
|
}
|
||||||
|
@ -867,9 +867,8 @@ impl IndexScheduler {
|
|||||||
/// Create a new index without any associated task.
|
/// Create a new index without any associated task.
|
||||||
pub fn create_raw_index(&self, name: &str) -> Result<Index> {
|
pub fn create_raw_index(&self, name: &str) -> Result<Index> {
|
||||||
let wtxn = self.env.write_txn()?;
|
let wtxn = self.env.write_txn()?;
|
||||||
let created_at = Some(time::OffsetDateTime::now_utc());
|
let date = Some(( time::OffsetDateTime::now_utc(), time::OffsetDateTime::now_utc() ));
|
||||||
let updated_at = Some(time::OffsetDateTime::now_utc());
|
let index = self.index_mapper.create_index(wtxn, name, date)?;
|
||||||
let index = self.index_mapper.create_index(wtxn, name, created_at, updated_at)?;
|
|
||||||
|
|
||||||
Ok(index)
|
Ok(index)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user