baloo runner: Clean up unneeded usage of QTimer and QDBusContext

The min letter count property is set to 3, which means that shorter queries will not be
sent to the runner. Consequently we can remove all of the code which has worked around
the issue of short queries taking much CPU power and delaying the runner.
wilder-5.24
Alexander Lohnau 5 years ago
parent c923422abb
commit f7efe4ea24
No known key found for this signature in database
GPG Key ID: 1F58708D54A003E7
  1. 56
      runners/baloo/baloosearchrunner.cpp
  2. 9
      runners/baloo/baloosearchrunner.h

@ -58,11 +58,7 @@ int main(int argc, char **argv)
SearchRunner::SearchRunner(QObject *parent)
: QObject(parent)
, m_timer(new QTimer(this))
{
m_timer->setSingleShot(true);
connect(m_timer, &QTimer::timeout, this, &SearchRunner::performMatch);
new Krunner1Adaptor(this);
qDBusRegisterMetaType<RemoteMatch>();
qDBusRegisterMetaType<RemoteMatches>();
@ -89,56 +85,26 @@ RemoteMatches SearchRunner::Match(const QString &searchTerm)
if (searchTerm.startsWith(QLatin1Char('='))) {
return RemoteMatches();
}
setDelayedReply(true);
if (m_lastRequest.type() != QDBusMessage::InvalidMessage) {
QDBusConnection::sessionBus().send(m_lastRequest.createReply(QVariantList()));
}
m_lastRequest = message();
m_searchTerm = searchTerm;
// Baloo (as of 2014-11-20) is single threaded. It has an internal mutex which results in
// queries being queued one after another. Also, Baloo is really really slow for small queries
// For example - on my SSD, it takes about 1.4 seconds for 'f' with an SSD.
// When searching for "fire", it results in "f", "fi", "fir" and then "fire" being searched
// We're therefore hacking around this by having a small delay for very short queries so that
// they do not get queued internally in Baloo
//
int waitTimeMs = 0;
if (searchTerm.length() <= 3) {
waitTimeMs = 100;
}
// we're still using the event delayed call even when the length is < 3 so that if we have multiple Match() calls in our DBus queue, we only process the
// last one
m_timer->start(waitTimeMs);
return RemoteMatches();
}
void SearchRunner::performMatch()
{
// Filter out duplicates
QSet<QUrl> foundUrls;
// The location runner handles file paths, otherwise we would end up with duplicate entries
QFileInfo fileInfo(KShell::tildeExpand(m_searchTerm));
QFileInfo fileInfo(KShell::tildeExpand(searchTerm));
if (fileInfo.exists()) {
foundUrls << QUrl::fromLocalFile(fileInfo.absoluteFilePath());
}
RemoteMatches matches;
matches << matchInternal(m_searchTerm, QStringLiteral("Audio"), i18n("Audio"), foundUrls);
matches << matchInternal(m_searchTerm, QStringLiteral("Image"), i18n("Image"), foundUrls);
matches << matchInternal(m_searchTerm, QStringLiteral("Video"), i18n("Video"), foundUrls);
matches << matchInternal(m_searchTerm, QStringLiteral("Spreadsheet"), i18n("Spreadsheet"), foundUrls);
matches << matchInternal(m_searchTerm, QStringLiteral("Presentation"), i18n("Presentation"), foundUrls);
matches << matchInternal(m_searchTerm, QStringLiteral("Folder"), i18n("Folder"), foundUrls);
matches << matchInternal(m_searchTerm, QStringLiteral("Document"), i18n("Document"), foundUrls);
matches << matchInternal(m_searchTerm, QStringLiteral("Archive"), i18n("Archive"), foundUrls);
QDBusConnection::sessionBus().send(m_lastRequest.createReply(QVariant::fromValue(matches)));
m_lastRequest = QDBusMessage();
matches << matchInternal(searchTerm, QStringLiteral("Audio"), i18n("Audio"), foundUrls);
matches << matchInternal(searchTerm, QStringLiteral("Image"), i18n("Image"), foundUrls);
matches << matchInternal(searchTerm, QStringLiteral("Video"), i18n("Video"), foundUrls);
matches << matchInternal(searchTerm, QStringLiteral("Spreadsheet"), i18n("Spreadsheet"), foundUrls);
matches << matchInternal(searchTerm, QStringLiteral("Presentation"), i18n("Presentation"), foundUrls);
matches << matchInternal(searchTerm, QStringLiteral("Folder"), i18n("Folder"), foundUrls);
matches << matchInternal(searchTerm, QStringLiteral("Document"), i18n("Document"), foundUrls);
matches << matchInternal(searchTerm, QStringLiteral("Archive"), i18n("Archive"), foundUrls);
return matches;
}
RemoteMatches SearchRunner::matchInternal(const QString &searchTerm, const QString &type, const QString &category, QSet<QUrl> &foundUrls)

@ -29,9 +29,7 @@
#include "dbusutils_p.h"
#include <KRunner/QueryMatch>
class QTimer;
class SearchRunner : public QObject, protected QDBusContext
class SearchRunner : public QObject
{
Q_OBJECT
@ -44,12 +42,7 @@ public:
void Run(const QString &id, const QString &actionId);
private:
void performMatch();
RemoteMatches matchInternal(const QString &searchTerm, const QString &type, const QString &category, QSet<QUrl> &foundUrls);
QDBusMessage m_lastRequest;
QString m_searchTerm;
QTimer *m_timer = nullptr;
};
#endif // _BALOO_SEARCH_RUNNER_H_

Loading…
Cancel
Save