Turn off parallel SQL updates for MySQL.

This commit is contained in:
Martin Rotter 2016-06-03 08:22:37 +02:00
parent 6d42687689
commit 0a8ff1a0cc
4 changed files with 31 additions and 2 deletions

View File

@ -41,7 +41,7 @@ bool FeedDownloader::isUpdateRunning() const {
}
void FeedDownloader::updateFeeds(const QList<Feed*> &feeds) {
qDebug().nospace() << "Performing feed updates in thread: \'" << QThread::currentThreadId() << "\'.";
qDebug().nospace() << "Starting feed updates from worker in thread: \'" << QThread::currentThreadId() << "\'.";
// It may be good to disable "stop" action when batch feed update
// starts.

View File

@ -40,7 +40,7 @@
Application::Application(const QString &id, int &argc, char **argv)
: QtSingleApplication(id, argc, argv),
m_updateFeedsLock(NULL), m_feedServices(QList<ServiceEntryPoint*>()), m_userActions(QList<QAction*>()), m_mainForm(NULL),
m_updateFeedsLock(NULL), m_updateMessagesLock(NULL), m_feedServices(QList<ServiceEntryPoint*>()), m_userActions(QList<QAction*>()), m_mainForm(NULL),
m_trayIcon(NULL), m_settings(NULL), m_system(NULL), m_skins(NULL),
m_localization(NULL), m_icons(NULL), m_database(NULL), m_downloadManager(NULL) {
connect(this, SIGNAL(aboutToQuit()), this, SLOT(onAboutToQuit()));
@ -123,6 +123,16 @@ Mutex *Application::feedUpdateLock() {
return m_updateFeedsLock.data();
}
Mutex *Application::messageUpdateLock() {
if (m_updateMessagesLock.isNull()) {
// NOTE: Cannot use parent hierarchy because this method can be usually called
// from any thread.
m_updateMessagesLock.reset(new Mutex());
}
return m_updateMessagesLock.data();
}
void Application::backupDatabaseSettings(bool backup_database, bool backup_settings,
const QString &target_path, const QString &backup_name) {
if (!QFileInfo(target_path).isWritable()) {

View File

@ -112,6 +112,7 @@ class Application : public QtSingleApplication {
// Access to application-wide close lock.
Mutex *feedUpdateLock();
Mutex *messageUpdateLock();
inline FormMain *mainForm() {
return m_mainForm;
@ -184,6 +185,8 @@ class Application : public QtSingleApplication {
// tries to lock the lock for writing), then no other
// action will be allowed to lock for reading.
QScopedPointer<Mutex> m_updateFeedsLock;
QScopedPointer<Mutex> m_updateMessagesLock;
QList<ServiceEntryPoint*> m_feedServices;
QList<QAction*> m_userActions;
FormMain *m_mainForm;

View File

@ -19,10 +19,13 @@
#include "definitions/definitions.h"
#include "miscellaneous/application.h"
#include "miscellaneous/mutex.h"
#include "miscellaneous/databasequeries.h"
#include "services/abstract/recyclebin.h"
#include "services/abstract/serviceroot.h"
#include <QThread>
Feed::Feed(RootItem *parent)
: RootItem(parent), m_url(QString()), m_status(Normal), m_autoUpdateType(DefaultAutoUpdate),
@ -131,6 +134,8 @@ void Feed::updateCounts(bool including_total_count) {
}
void Feed::run() {
qDebug().nospace() << "Updating feed " << customId() << " in thread: \'" << QThread::currentThreadId() << "\'.";
emit updated(update());
}
@ -139,6 +144,13 @@ int Feed::updateMessages(const QList<Message> &messages) {
int account_id = getParentServiceRoot()->accountId();
bool anything_updated = false;
bool ok;
// MySQL seems to be more error prone with transactions when called
// from more threads in the same time. SQLite does not have that limitation.
if (qApp->database()->activeDatabaseDriver() == DatabaseFactory::MYSQL) {
qApp->messageUpdateLock()->lock();
}
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
int updated_messages = DatabaseQueries::updateMessages(database, messages, custom_id, account_id, url(),
&anything_updated, &ok);
@ -164,5 +176,9 @@ int Feed::updateMessages(const QList<Message> &messages) {
getParentServiceRoot()->itemChanged(items_to_update);
}
if (qApp->database()->activeDatabaseDriver() == DatabaseFactory::MYSQL) {
qApp->messageUpdateLock()->unlock();
}
return updated_messages;
}