From f51eb46c699c1a1b6d913b59d7d388c0c45cbf78 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Tue, 9 Mar 2021 10:24:27 +0100 Subject: [PATCH] Use the RoaringBitmapLenCodec to retrieve the count of documents --- milli/src/index.rs | 11 ++++++----- milli/src/update/clear_documents.rs | 2 +- milli/src/update/delete_documents.rs | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/milli/src/index.rs b/milli/src/index.rs index 7b83d69fc..c0a00080e 100644 --- a/milli/src/index.rs +++ b/milli/src/index.rs @@ -118,6 +118,12 @@ impl Index { 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 { + let count = self.main.get::<_, Str, RoaringBitmapLenCodec>(rtxn, DOCUMENTS_IDS_KEY)?; + Ok(count.unwrap_or_default()) + } + /* primary key */ /// 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) } - /// Returns the number of documents indexed in the database. - pub fn number_of_documents(&self, rtxn: &RoTxn) -> anyhow::Result { - Ok(self.documents_ids(rtxn).map(|docids| docids.len() as usize)?) - } - pub fn facets_distribution<'a>(&'a self, rtxn: &'a RoTxn) -> FacetDistribution<'a> { FacetDistribution::new(rtxn, self) } diff --git a/milli/src/update/clear_documents.rs b/milli/src/update/clear_documents.rs index 1523a95b2..82e35d703 100644 --- a/milli/src/update/clear_documents.rs +++ b/milli/src/update/clear_documents.rs @@ -17,7 +17,7 @@ impl<'t, 'u, 'i> ClearDocuments<'t, 'u, 'i> { ClearDocuments { wtxn, index, _update_id: update_id } } - pub fn execute(self) -> anyhow::Result { + pub fn execute(self) -> anyhow::Result { let Index { env: _env, main: _main, diff --git a/milli/src/update/delete_documents.rs b/milli/src/update/delete_documents.rs index 5430bb3af..d1007376a 100644 --- a/milli/src/update/delete_documents.rs +++ b/milli/src/update/delete_documents.rs @@ -51,7 +51,7 @@ impl<'t, 'u, 'i> DeleteDocuments<'t, 'u, 'i> { Some(docid) } - pub fn execute(self) -> anyhow::Result { + pub fn execute(self) -> anyhow::Result { // We retrieve the current documents ids that are in the database. let mut documents_ids = self.index.documents_ids(self.wtxn)?; @@ -308,7 +308,7 @@ impl<'t, 'u, 'i> DeleteDocuments<'t, 'u, 'i> { drop(iter); - Ok(self.documents_ids.len() as usize) + Ok(self.documents_ids.len()) } }