diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2019-02-04 00:24:39 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2019-02-11 03:22:56 +0100 |
commit | 8a4bc0eba41552a84b9c3d3df9e158c66cfe408b (patch) | |
tree | 79d8d4ef9e08322cf1c02383c04559941f7f5451 /lib/domain/libimagwiki/src/wiki.rs | |
parent | c29e05bc2583d5126f3100d3d7908f742143155f (diff) |
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 <mail@beyermatthias.de>
Diffstat (limited to 'lib/domain/libimagwiki/src/wiki.rs')
-rw-r--r-- | lib/domain/libimagwiki/src/wiki.rs | 51 |
1 files 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<WikiIdIterator> { - let filter = IdIsInWikiFilter(self.1); - Ok(WikiIdIterator(self.0.entries()?.without_store().with_store(self.0), filter)) + pub fn all_ids(&self) -> Result<StoreIdIterator> { + self.0.entries().map(|iter| iter.in_collection("wiki").without_store()) } pub fn delete_entry<EN: AsRef<str>>(&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<StoreId>; - - fn next(&mut self) -> Option<Self::Item> { - 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<StoreId> for IdIsInWikiFilter<'a> { - fn filter(&self, id: &StoreId) -> bool { - id.is_in_collection(&["wiki", &self.0]) - } -} - -impl<'a> Filter<Entry> for IdIsInWikiFilter<'a> { - fn filter(&self, e: &Entry) -> bool { - e.get_location().is_in_collection(&["wiki", &self.0]) - } -} - - |