mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-01-11 05:54:30 +01:00
lazy load update store
This commit is contained in:
parent
53cf500e36
commit
2ae90f9c5d
@ -301,13 +301,33 @@ impl UpdateStoreStore for MapUpdateStoreStore {
|
||||
}
|
||||
|
||||
async fn get(&self, uuid: &Uuid) -> Result<Option<Arc<UpdateStore>>> {
|
||||
Ok(self.db.read().await.get(uuid).cloned())
|
||||
// attemps to get pre-loaded ref to the index
|
||||
match self.db.read().await.get(uuid) {
|
||||
Some(uuid) => Ok(Some(uuid.clone())),
|
||||
None => {
|
||||
// otherwise we try to check if it exists, and load it.
|
||||
let path = self.path.clone().join(format!("updates-{}", uuid));
|
||||
if path.exists() {
|
||||
let index_handle = self.index_handle.clone();
|
||||
let mut options = heed::EnvOpenOptions::new();
|
||||
options.map_size(4096 * 100_000);
|
||||
let store = UpdateStore::open(options, &path, move |meta, file| {
|
||||
futures::executor::block_on(index_handle.update(meta, file))
|
||||
})
|
||||
.unwrap();
|
||||
self.db.write().await.insert(uuid.clone(), store.clone());
|
||||
Ok(Some(store))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn delete(&self, uuid: &Uuid) -> Result<Option<Arc<UpdateStore>>> {
|
||||
let store = self.db.write().await.remove(&uuid);
|
||||
if store.is_some() {
|
||||
let path = self.path.clone().join(format!("updates-{}", uuid));
|
||||
if store.is_some() || path.exists() {
|
||||
remove_dir_all(path).unwrap();
|
||||
}
|
||||
Ok(store)
|
||||
|
Loading…
x
Reference in New Issue
Block a user