Merge pull request #105 from meilisearch/optimize-number-of-documents

Optimize the number_of_documents function
This commit is contained in:
Clément Renault 2021-03-10 10:39:12 +01:00 committed by GitHub
commit c53be51460
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 8 deletions

View File

@ -118,6 +118,12 @@ impl Index {
Ok(self.main.get::<_, Str, RoaringBitmapCodec>(rtxn, DOCUMENTS_IDS_KEY)?.unwrap_or_default()) Ok(self.main.get::<_, Str, RoaringBitmapCodec>(rtxn, DOCUMENTS_IDS_KEY)?.unwrap_or_default())
} }
/// Returns the number of documents indexed in the database.
pub fn number_of_documents(&self, rtxn: &RoTxn) -> anyhow::Result<u64> {
let count = self.main.get::<_, Str, RoaringBitmapLenCodec>(rtxn, DOCUMENTS_IDS_KEY)?;
Ok(count.unwrap_or_default())
}
/* primary key */ /* primary key */
/// Writes the documents primary key, this is the field name that is used to store the id. /// Writes the documents primary key, this is the field name that is used to store the id.
@ -380,11 +386,6 @@ impl Index {
Ok(documents) Ok(documents)
} }
/// Returns the number of documents indexed in the database.
pub fn number_of_documents(&self, rtxn: &RoTxn) -> anyhow::Result<usize> {
Ok(self.documents_ids(rtxn).map(|docids| docids.len() as usize)?)
}
pub fn facets_distribution<'a>(&'a self, rtxn: &'a RoTxn) -> FacetDistribution<'a> { pub fn facets_distribution<'a>(&'a self, rtxn: &'a RoTxn) -> FacetDistribution<'a> {
FacetDistribution::new(rtxn, self) FacetDistribution::new(rtxn, self)
} }

View File

@ -17,7 +17,7 @@ impl<'t, 'u, 'i> ClearDocuments<'t, 'u, 'i> {
ClearDocuments { wtxn, index, _update_id: update_id } ClearDocuments { wtxn, index, _update_id: update_id }
} }
pub fn execute(self) -> anyhow::Result<usize> { pub fn execute(self) -> anyhow::Result<u64> {
let Index { let Index {
env: _env, env: _env,
main: _main, main: _main,

View File

@ -51,7 +51,7 @@ impl<'t, 'u, 'i> DeleteDocuments<'t, 'u, 'i> {
Some(docid) Some(docid)
} }
pub fn execute(self) -> anyhow::Result<usize> { pub fn execute(self) -> anyhow::Result<u64> {
// We retrieve the current documents ids that are in the database. // We retrieve the current documents ids that are in the database.
let mut documents_ids = self.index.documents_ids(self.wtxn)?; let mut documents_ids = self.index.documents_ids(self.wtxn)?;
@ -308,7 +308,7 @@ impl<'t, 'u, 'i> DeleteDocuments<'t, 'u, 'i> {
drop(iter); drop(iter);
Ok(self.documents_ids.len() as usize) Ok(self.documents_ids.len())
} }
} }