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>
This commit is contained in:
Matthias Beyer 2019-02-04 00:24:39 +01:00
parent c29e05bc25
commit 8a4bc0eba4

View file

@ -19,14 +19,10 @@
use std::path::PathBuf; use std::path::PathBuf;
use filters::filter::Filter;
use libimagstore::store::Store; use libimagstore::store::Store;
use libimagstore::store::Entry;
use libimagstore::store::FileLockEntry; use libimagstore::store::FileLockEntry;
use libimagstore::storeid::IntoStoreId; use libimagstore::storeid::IntoStoreId;
use libimagstore::storeid::StoreId; use libimagstore::storeid::StoreIdIterator;
use libimagstore::storeid::StoreIdIteratorWithStore;
use libimagentrylink::internal::InternalLinker; use libimagentrylink::internal::InternalLinker;
use failure::Fallible as Result; use failure::Fallible as Result;
@ -95,9 +91,8 @@ impl<'a, 'b> Wiki<'a, 'b> {
entry.add_internal_link(&mut index).map(|_| entry) entry.add_internal_link(&mut index).map(|_| entry)
} }
pub fn all_ids(&self) -> Result<WikiIdIterator> { pub fn all_ids(&self) -> Result<StoreIdIterator> {
let filter = IdIsInWikiFilter(self.1); self.0.entries().map(|iter| iter.in_collection("wiki").without_store())
Ok(WikiIdIterator(self.0.entries()?.without_store().with_store(self.0), filter))
} }
pub fn delete_entry<EN: AsRef<str>>(&self, entry_name: EN) -> Result<()> { 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])
}
}