mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-27 04:25:06 +08:00
feat: Improve the number of documents counting
This commit is contained in:
parent
707e2f4d77
commit
2006259a23
@ -54,7 +54,7 @@ impl DocumentsIndex {
|
||||
Ok(DocumentFieldsIter(iter))
|
||||
}
|
||||
|
||||
pub fn len(&self) -> RocksDbResult<usize> {
|
||||
pub fn len(&self) -> RocksDbResult<u64> {
|
||||
let mut last_document_id = None;
|
||||
let mut count = 0;
|
||||
|
||||
|
@ -164,7 +164,7 @@ fn last_update_id(
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct IndexStats {
|
||||
pub number_of_words: usize,
|
||||
pub number_of_documents: usize,
|
||||
pub number_of_documents: u64,
|
||||
pub number_attrs_in_ranked_map: usize,
|
||||
}
|
||||
|
||||
@ -192,6 +192,7 @@ pub(crate) struct Cache {
|
||||
pub synonyms: Arc<fst::Set>,
|
||||
pub schema: Schema,
|
||||
pub ranked_map: RankedMap,
|
||||
pub number_of_documents: u64,
|
||||
}
|
||||
|
||||
impl Index {
|
||||
@ -241,7 +242,9 @@ impl Index {
|
||||
None => RankedMap::default(),
|
||||
};
|
||||
|
||||
let cache = Cache { words, synonyms, schema, ranked_map };
|
||||
let number_of_documents = documents_index.len()?;
|
||||
|
||||
let cache = Cache { words, synonyms, schema, ranked_map, number_of_documents };
|
||||
let cache = Arc::new(ArcSwap::from_pointee(cache));
|
||||
|
||||
let last_update_id = last_update_id(&updates_index, &updates_results_index)?;
|
||||
@ -280,7 +283,7 @@ impl Index {
|
||||
let cache = self.cache.load();
|
||||
Ok(IndexStats {
|
||||
number_of_words: cache.words.len(),
|
||||
number_of_documents: self.documents_index.len()?,
|
||||
number_of_documents: cache.number_of_documents,
|
||||
number_attrs_in_ranked_map: cache.ranked_map.len(),
|
||||
})
|
||||
}
|
||||
@ -319,6 +322,10 @@ impl Index {
|
||||
self.custom_settings_index.clone()
|
||||
}
|
||||
|
||||
pub fn number_of_documents(&self) -> u64 {
|
||||
self.cache.load().number_of_documents
|
||||
}
|
||||
|
||||
pub fn documents_addition<D>(&self) -> DocumentsAddition<D> {
|
||||
DocumentsAddition::new(self)
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ pub fn apply_documents_addition(
|
||||
let synonyms = cache.synonyms.clone();
|
||||
let schema = cache.schema.clone();
|
||||
|
||||
let cache = Cache { words, synonyms, schema, ranked_map };
|
||||
let cache = Cache { words, synonyms, schema, ranked_map, number_of_documents };
|
||||
index.cache.store(Arc::new(cache));
|
||||
|
||||
Ok(())
|
||||
|
@ -143,7 +143,7 @@ pub fn apply_documents_deletion(
|
||||
let synonyms = cache.synonyms.clone();
|
||||
let schema = cache.schema.clone();
|
||||
|
||||
let cache = Cache { words, synonyms, schema, ranked_map };
|
||||
let cache = Cache { words, synonyms, schema, ranked_map, number_of_documents };
|
||||
index.cache.store(Arc::new(cache));
|
||||
|
||||
Ok(())
|
||||
|
@ -85,8 +85,9 @@ pub fn apply_synonyms_addition(
|
||||
let ranked_map = cache.ranked_map.clone();
|
||||
let synonyms = Arc::new(synonyms);
|
||||
let schema = cache.schema.clone();
|
||||
let number_of_documents = cache.number_of_documents;
|
||||
|
||||
let cache = Cache { words, synonyms, schema, ranked_map };
|
||||
let cache = Cache { words, synonyms, schema, ranked_map, number_of_documents };
|
||||
index.cache.store(Arc::new(cache));
|
||||
|
||||
Ok(())
|
||||
|
@ -128,8 +128,9 @@ pub fn apply_synonyms_deletion(
|
||||
let ranked_map = cache.ranked_map.clone();
|
||||
let synonyms = Arc::new(synonyms);
|
||||
let schema = cache.schema.clone();
|
||||
let number_of_documents = cache.number_of_documents;
|
||||
|
||||
let cache = Cache { words, synonyms, schema, ranked_map };
|
||||
let cache = Cache { words, synonyms, schema, ranked_map, number_of_documents };
|
||||
index.cache.store(Arc::new(cache));
|
||||
|
||||
Ok(())
|
||||
|
Loading…
Reference in New Issue
Block a user