mirror of
https://github.com/kiwix/libkiwix.git
synced 2026-10-17 06:35:11 -04:00
Use the newly introduced searcherCache for multizim searcher.
This commit is contained in:
1 parent
fd0edbba80
commit
854623618c
3 files changed
+20
-18
No files matched your search
+10
-6
@@ -304,17 +304,21 @@ std::shared_ptr<zim::Archive> Library::getArchiveById(const std::string& id)
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<zim::Searcher> Library::getSearcherById(const std::string& id)
|
||||
std::shared_ptr<zim::Searcher> Library::getSearcherByIds(const BookIdSet& ids)
|
||||
{
|
||||
std::set<std::string> ids {id};
|
||||
assert(!ids.empty());
|
||||
try {
|
||||
return mp_impl->mp_searcherCache->getOrPut(ids,
|
||||
[&](){
|
||||
auto archive = getArchiveById(id);
|
||||
if(!archive) {
|
||||
throw std::invalid_argument("");
|
||||
std::vector<zim::Archive> archives;
|
||||
for(auto& id:ids) {
|
||||
auto archive = getArchiveById(id);
|
||||
if(!archive) {
|
||||
throw std::invalid_argument("");
|
||||
}
|
||||
archives.push_back(*archive);
|
||||
}
|
||||
return std::make_shared<zim::Searcher>(*archive);
|
||||
return std::make_shared<zim::Searcher>(archives);
|
||||
});
|
||||
} catch (std::invalid_argument&) {
|
||||
return nullptr;
|
||||
|
||||
Reference in new issue
Block a user