1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

SqlDatabase: Skip copy when executing query on main thread

This commit is contained in:
David Rosca 2016-12-11 11:05:51 +01:00
parent 5fb492d033
commit d19f5de7bf
2 changed files with 8 additions and 2 deletions

View File

@ -19,6 +19,7 @@
#include <QThread> #include <QThread>
#include <QMutexLocker> #include <QMutexLocker>
#include <QApplication>
#include <QtConcurrent/QtConcurrentRun> #include <QtConcurrent/QtConcurrentRun>
@ -54,8 +55,13 @@ QSqlDatabase SqlDatabase::databaseForThread(QThread* thread)
return m_databases[thread]; return m_databases[thread];
} }
QSqlQuery SqlDatabase::exec(const QSqlQuery &query) QSqlQuery SqlDatabase::exec(QSqlQuery &query)
{ {
if (QThread::currentThread() == qApp->thread()) {
query.exec();
return query;
}
QSqlQuery out(databaseForThread(QThread::currentThread())); QSqlQuery out(databaseForThread(QThread::currentThread()));
out.prepare(query.lastQuery()); out.prepare(query.lastQuery());

View File

@ -39,7 +39,7 @@ public:
QSqlDatabase databaseForThread(QThread* thread); QSqlDatabase databaseForThread(QThread* thread);
// Executes query using correct database for current thread // Executes query using correct database for current thread
QSqlQuery exec(const QSqlQuery &query); QSqlQuery exec(QSqlQuery &query);
// Executes query asynchronously on one thread from QThreadPool // Executes query asynchronously on one thread from QThreadPool
QFuture<QSqlQuery> execAsync(const QSqlQuery &query); QFuture<QSqlQuery> execAsync(const QSqlQuery &query);