From f7efe4ea24ae944ead6077ed2697709f2dfd3e48 Mon Sep 17 00:00:00 2001 From: Alexander Lohnau Date: Tue, 13 Jul 2021 19:56:36 +0200 Subject: [PATCH] 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. --- runners/baloo/baloosearchrunner.cpp | 56 ++++++----------------------- runners/baloo/baloosearchrunner.h | 9 +---- 2 files changed, 12 insertions(+), 53 deletions(-) diff --git a/runners/baloo/baloosearchrunner.cpp b/runners/baloo/baloosearchrunner.cpp index 4e2544c0e..aebd9dba7 100644 --- a/runners/baloo/baloosearchrunner.cpp +++ b/runners/baloo/baloosearchrunner.cpp @@ -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(); qDBusRegisterMetaType(); @@ -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 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 &foundUrls) diff --git a/runners/baloo/baloosearchrunner.h b/runners/baloo/baloosearchrunner.h index 2a3446238..5c1dfda84 100644 --- a/runners/baloo/baloosearchrunner.h +++ b/runners/baloo/baloosearchrunner.h @@ -29,9 +29,7 @@ #include "dbusutils_p.h" #include -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 &foundUrls); - - QDBusMessage m_lastRequest; - QString m_searchTerm; - QTimer *m_timer = nullptr; }; #endif // _BALOO_SEARCH_RUNNER_H_