From 8a4bc0eba41552a84b9c3d3df9e158c66cfe408b Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 4 Feb 2019 00:24:39 +0100 Subject: [PATCH] Simplify implementation of Wiki::all_ids() This way we alter the underlying iterator for all wiki entries to only iterate in the "wiki" collection of the store, which results in fewer disk access because the internal iterator does not yield all pathes from the store before filtering them. Code which was used to implement the filter was removed (also from the public interface of the library). Signed-off-by: Matthias Beyer --- lib/domain/libimagwiki/src/wiki.rs | 51 ++---------------------------- 1 file changed, 3 insertions(+), 48 deletions(-) diff --git a/lib/domain/libimagwiki/src/wiki.rs b/lib/domain/libimagwiki/src/wiki.rs index 0bd3542c..33a6bc47 100644 --- a/lib/domain/libimagwiki/src/wiki.rs +++ b/lib/domain/libimagwiki/src/wiki.rs @@ -19,14 +19,10 @@ use std::path::PathBuf; -use filters::filter::Filter; - use libimagstore::store::Store; -use libimagstore::store::Entry; use libimagstore::store::FileLockEntry; use libimagstore::storeid::IntoStoreId; -use libimagstore::storeid::StoreId; -use libimagstore::storeid::StoreIdIteratorWithStore; +use libimagstore::storeid::StoreIdIterator; use libimagentrylink::internal::InternalLinker; use failure::Fallible as Result; @@ -95,9 +91,8 @@ impl<'a, 'b> Wiki<'a, 'b> { entry.add_internal_link(&mut index).map(|_| entry) } - pub fn all_ids(&self) -> Result { - let filter = IdIsInWikiFilter(self.1); - Ok(WikiIdIterator(self.0.entries()?.without_store().with_store(self.0), filter)) + pub fn all_ids(&self) -> Result { + self.0.entries().map(|iter| iter.in_collection("wiki").without_store()) } pub fn delete_entry>(&self, entry_name: EN) -> Result<()> { @@ -107,43 +102,3 @@ impl<'a, 'b> Wiki<'a, 'b> { } } -pub struct WikiIdIterator<'a>(StoreIdIteratorWithStore<'a>, IdIsInWikiFilter<'a>); - -impl<'a> Iterator for WikiIdIterator<'a> { - type Item = Result; - - fn next(&mut self) -> Option { - while let Some(next) = self.0.next() { - match next { - Ok(next) => if self.1.filter(&next) { - return Some(Ok(next)); - }, - Err(e) => return Some(Err(e)), - } - } - - None - } -} - -pub struct IdIsInWikiFilter<'a>(&'a str); - -impl<'a> IdIsInWikiFilter<'a> { - pub fn new(wiki_name: &'a str) -> Self { - IdIsInWikiFilter(wiki_name) - } -} - -impl<'a> Filter for IdIsInWikiFilter<'a> { - fn filter(&self, id: &StoreId) -> bool { - id.is_in_collection(&["wiki", &self.0]) - } -} - -impl<'a> Filter for IdIsInWikiFilter<'a> { - fn filter(&self, e: &Entry) -> bool { - e.get_location().is_in_collection(&["wiki", &self.0]) - } -} - -