mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-24 04:32:15 -04:00
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:
parent
3582ab03e3
commit
4b9cc80f66
@ -83,7 +83,7 @@ function init() {
|
|||||||
futurCall = null;
|
futurCall = null;
|
||||||
function setSearch(value) {
|
function setSearch(value) {
|
||||||
clearTimeout(futurCall);
|
clearTimeout(futurCall);
|
||||||
futurCall = setTimeout(function(){contentManager.setSearch(value)}, 200);
|
futurCall = setTimeout(function(){contentManager.setSearch(value)}, 100);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<style>
|
<style>
|
||||||
|
@ -221,8 +221,6 @@ void ContentManager::updateRemoteLibrary() {
|
|||||||
QUrlQuery query;
|
QUrlQuery query;
|
||||||
query.addQueryItem("lang", m_currentLanguage);
|
query.addQueryItem("lang", m_currentLanguage);
|
||||||
query.addQueryItem("count", QString::number(0));
|
query.addQueryItem("count", QString::number(0));
|
||||||
if (!m_searchQuery.isEmpty())
|
|
||||||
query.addQueryItem("q", m_searchQuery);
|
|
||||||
QUrl url;
|
QUrl url;
|
||||||
url.setScheme("http");
|
url.setScheme("http");
|
||||||
url.setHost(CATALOG_HOST);
|
url.setHost(CATALOG_HOST);
|
||||||
@ -242,24 +240,18 @@ void ContentManager::updateRemoteLibrary() {
|
|||||||
void ContentManager::setSearch(const QString &search)
|
void ContentManager::setSearch(const QString &search)
|
||||||
{
|
{
|
||||||
m_searchQuery = search;
|
m_searchQuery = search;
|
||||||
if (m_local)
|
|
||||||
emit(booksChanged());
|
emit(booksChanged());
|
||||||
else
|
|
||||||
emit(remoteParamsChanged());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList ContentManager::getBookIds() {
|
QStringList ContentManager::getBookIds() {
|
||||||
if (m_local) {
|
if (m_local) {
|
||||||
return mp_library->listBookIds(m_searchQuery);
|
return mp_library->listBookIds(m_searchQuery);
|
||||||
} else {
|
} else {
|
||||||
auto bookIds = m_remoteLibrary.getBooksIds();
|
auto bookIds = m_remoteLibrary.listBooksIds(kiwix::REMOTE, kiwix::UNSORTED,
|
||||||
|
m_searchQuery.toStdString());
|
||||||
QStringList list;
|
QStringList list;
|
||||||
for(auto& bookId:bookIds) {
|
for(auto& bookId:bookIds) {
|
||||||
try{
|
|
||||||
list.append(QString::fromStdString(bookId));
|
list.append(QString::fromStdString(bookId));
|
||||||
} catch (out_of_range&) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user