Do not do an extra request to search book in the remote library.

When doing a search in the library, we know for sure that the result will
be a subset of the library we have (without query). So we can do the
search locally (through the books we already have in cache) instead of
doing another request.
This commit is contained in:
Matthieu Gautier 2018-12-11 12:08:22 +01:00
parent 3582ab03e3
commit 4b9cc80f66
2 changed files with 5 additions and 13 deletions

View File

@ -83,7 +83,7 @@ function init() {
futurCall = null;
function setSearch(value) {
clearTimeout(futurCall);
futurCall = setTimeout(function(){contentManager.setSearch(value)}, 200);
futurCall = setTimeout(function(){contentManager.setSearch(value)}, 100);
}
</script>
<style>

View File

@ -221,8 +221,6 @@ void ContentManager::updateRemoteLibrary() {
QUrlQuery query;
query.addQueryItem("lang", m_currentLanguage);
query.addQueryItem("count", QString::number(0));
if (!m_searchQuery.isEmpty())
query.addQueryItem("q", m_searchQuery);
QUrl url;
url.setScheme("http");
url.setHost(CATALOG_HOST);
@ -242,24 +240,18 @@ void ContentManager::updateRemoteLibrary() {
void ContentManager::setSearch(const QString &search)
{
m_searchQuery = search;
if (m_local)
emit(booksChanged());
else
emit(remoteParamsChanged());
}
QStringList ContentManager::getBookIds() {
if (m_local) {
return mp_library->listBookIds(m_searchQuery);
} else {
auto bookIds = m_remoteLibrary.getBooksIds();
auto bookIds = m_remoteLibrary.listBooksIds(kiwix::REMOTE, kiwix::UNSORTED,
m_searchQuery.toStdString());
QStringList list;
for(auto& bookId:bookIds) {
try{
list.append(QString::fromStdString(bookId));
} catch (out_of_range&) {
break;
}
}
return list;
}