From d9b01a49417fb7ce0d9898e3fe1f4fc0826eb11a Mon Sep 17 00:00:00 2001 From: Albert S Date: Sun, 2 Sep 2018 12:45:28 +0200 Subject: [PATCH] sql: only join content table if necessary --- gui/searchworker.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/gui/searchworker.cpp b/gui/searchworker.cpp index bf3b450..0ccceea 100644 --- a/gui/searchworker.cpp +++ b/gui/searchworker.cpp @@ -131,10 +131,20 @@ void SearchWorker::search(const QString &query) QSqlQuery dbquery(db); QVector results; QString whereSql = makeSql(tokenize(query)); - QString prep = - "SELECT file.path AS path, content.page AS page, file.mtime AS mtime FROM file INNER JOIN content ON file.id = " - "content.fileid INNER JOIN content_fts ON content.id = content_fts.ROWID WHERE 1=1 AND " + - whereSql + " ORDER By file.mtime DESC, content.page ASC"; + + QString prep; + // TODO: hack, as we don't wanna look into content and get redundant results, when we don't even care about content + if(whereSql.contains("content.")) + { + prep = "SELECT file.path AS path, content.page AS page, file.mtime AS mtime FROM file INNER JOIN content ON " + "file.id = content.fileid INNER JOIN content_fts ON content.id = content_fts.ROWID WHERE 1=1 AND " + + whereSql + " ORDER By file.mtime DESC, content.page ASC"; + } + else + { + prep = "SELECT file.path AS path, 0 as page, file.mtime AS mtime FROM file WHERE " + whereSql + + " ORDER by file.mtime DESC"; + } dbquery.prepare(prep); dbquery.exec(); qDebug() << "prepped: " << prep;