1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +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 <QMutexLocker>
#include <QApplication>
#include <QtConcurrent/QtConcurrentRun>
@ -54,8 +55,13 @@ QSqlDatabase SqlDatabase::databaseForThread(QThread* 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()));
out.prepare(query.lastQuery());

View File

@ -39,7 +39,7 @@ public:
QSqlDatabase databaseForThread(QThread* 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
QFuture<QSqlQuery> execAsync(const QSqlQuery &query);