feat: Improve the number of documents counting

This commit is contained in:
Clément Renault 2019-09-14 12:26:47 +02:00
parent 707e2f4d77
commit 2006259a23
No known key found for this signature in database
GPG Key ID: 0151CDAB43460DAE
6 changed files with 17 additions and 8 deletions

View File

@ -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;

View File

@ -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)
}

View File

@ -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(())

View File

@ -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(())

View File

@ -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(())

View File

@ -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(())