From ee8b6ab5092dea422e207b7c0c92f9eaf8e03788 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Thu, 20 Nov 2014 18:11:04 +0100 Subject: [PATCH] BalooSearchRunner: Add a delay for queries <= 3 characters Because Baloo is single threaded internally. Read the huge comment in the code. --- runners/baloo/baloosearchrunner.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/runners/baloo/baloosearchrunner.cpp b/runners/baloo/baloosearchrunner.cpp index 6b39b7a71..e6080c3a3 100644 --- a/runners/baloo/baloosearchrunner.cpp +++ b/runners/baloo/baloosearchrunner.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -130,6 +131,28 @@ void SearchRunner::match(Plasma::RunnerContext& context, const QString& type, void SearchRunner::match(Plasma::RunnerContext& context) { + const QString text = context.query(); + // + // 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 + // + if (text.length() <= 3) { + QEventLoop loop; + QTimer timer; + connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); + timer.setSingleShot(true); + timer.start(100); + loop.exec(); + + if (!context.isValid()) { + return; + } + } + match(context, QLatin1String("File/Audio"), i18n("Audio")); match(context, QLatin1String("File/Image"), i18n("Image")); match(context, QLatin1String("File/Document"), i18n("Document"));