Commit 947b03d6 authored by David Edmundson's avatar David Edmundson
Browse files

Guard BookmarksRunner thread use

Summary:
Krunner::match is performed in potentially multiple overlapping threads
as a user presses each character. Qt SQL is not thread safe according to
the docs or according to the numerous reports.

It's a bit of a blind patch, ideally we should only use the database in
the thread that opened it.

This patch at least this means queries will be queued which I think will
be enough.

CCBUG: 363136

Test Plan: Restarted krunner. Still saw my firefox bookmarks

Reviewers: #plasma, mart

Reviewed By: #plasma, mart

Subscribers: rempt, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D12683
parent 4f30ad34
......@@ -25,6 +25,7 @@
#include <QSqlQuery>
#include <QSqlError>
#include <QSqlRecord>
#include <QMutexLocker>
FetchSqlite::FetchSqlite(const QString &originalFilePath, const QString &copyTo, QObject *parent) :
QObject(parent), m_databaseFile(copyTo)
......@@ -49,6 +50,7 @@ FetchSqlite::~FetchSqlite()
void FetchSqlite::prepare()
{
QMutexLocker lock(&m_mutex);
m_db.setDatabaseName(m_databaseFile);
bool ok = m_db.open();
//qDebug() << "Sqlite Database " << m_databaseFile << " was opened: " << ok;
......@@ -59,6 +61,7 @@ void FetchSqlite::prepare()
void FetchSqlite::teardown()
{
QMutexLocker lock(&m_mutex);
m_db.close();
}
......@@ -69,6 +72,8 @@ QList<QVariantMap> FetchSqlite::query(BuildQuery *buildQuery, QMap<QString, QVar
QList<QVariantMap> FetchSqlite::query(const QString &sql, QMap<QString, QVariant> bindObjects)
{
QMutexLocker lock(&m_mutex);
//qDebug() << "query: " << sql;
QSqlQuery query(m_db);
query.prepare(sql);
......
......@@ -28,6 +28,7 @@
#include <QString>
#include <QObject>
#include <QMutex>
class BuildQuery {
......@@ -50,6 +51,7 @@ public:
private:
QString const m_databaseFile;
QMutex m_mutex;
QSqlDatabase m_db;
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment