From ffc9c7490034b6ef97bb6b836e91a98cc5cb17eb Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Mon, 9 Jan 2023 14:44:41 +0100 Subject: [PATCH] some cleanups, remove DB transactins support as it is now useless --- resources/desktop/rssguard.metainfo.xml.in | 2 +- src/librssguard/database/databasecleaner.cpp | 2 +- src/librssguard/database/databasequeries.cpp | 24 +--- .../gui/settings/settingsdatabase.cpp | 112 ++++++++++-------- .../gui/settings/settingsdatabase.ui | 26 +--- src/librssguard/miscellaneous/settings.cpp | 3 - src/librssguard/miscellaneous/settings.h | 3 - src/librssguard/services/abstract/feed.cpp | 2 - .../services/abstract/importantnode.cpp | 2 - src/librssguard/services/abstract/label.cpp | 1 - .../services/abstract/recyclebin.cpp | 2 - .../services/abstract/serviceroot.cpp | 11 +- .../services/abstract/unreadnode.cpp | 2 - .../services/gmail/gmailnetworkfactory.cpp | 1 - .../services/reddit/redditnetworkfactory.cpp | 1 - 15 files changed, 73 insertions(+), 121 deletions(-) diff --git a/resources/desktop/rssguard.metainfo.xml.in b/resources/desktop/rssguard.metainfo.xml.in index 9f4b74f4e..f1e7fbf94 100644 --- a/resources/desktop/rssguard.metainfo.xml.in +++ b/resources/desktop/rssguard.metainfo.xml.in @@ -60,7 +60,7 @@ - + @APP_LOW_NAME@ diff --git a/src/librssguard/database/databasecleaner.cpp b/src/librssguard/database/databasecleaner.cpp index 6265a6d25..db32291ae 100644 --- a/src/librssguard/database/databasecleaner.cpp +++ b/src/librssguard/database/databasecleaner.cpp @@ -11,7 +11,7 @@ DatabaseCleaner::DatabaseCleaner(QObject* parent) : QObject(parent) {} void DatabaseCleaner::purgeDatabaseData(CleanerOrders which_data) { - qDebugNN << LOGSEC_DB << "Performing database cleanup in thread: '" << QThread::currentThreadId() << "'."; + qDebugNN << LOGSEC_DB << "Performing database cleanup in thread:" << QUOTE_W_SPACE_DOT(QThread::currentThreadId()); // Inform everyone about the start of the process. emit purgeStarted(); diff --git a/src/librssguard/database/databasequeries.cpp b/src/librssguard/database/databasequeries.cpp index 5de60aa49..17a1422bf 100644 --- a/src/librssguard/database/databasequeries.cpp +++ b/src/librssguard/database/databasequeries.cpp @@ -1086,7 +1086,6 @@ QPair DatabaseQueries::updateMessages(QSqlDatabase db, return {0, 0}; } - bool use_transactions = qApp->settings()->value(GROUP(Database), SETTING(Database::UseTransactions)).toBool(); QPair updated_messages = {0, 0}; int account_id = feed->getParentServiceRoot()->accountId(); auto feed_custom_id = feed->customId(); @@ -1098,7 +1097,6 @@ QPair DatabaseQueries::updateMessages(QSqlDatabase db, QSqlQuery query_select_with_id(db); QSqlQuery query_update(db); QSqlQuery query_insert(db); - QSqlQuery query_begin_transaction(db); // Here we have query which will check for existence of the "same" message in given feed. // The two message are the "same" if: @@ -1148,12 +1146,6 @@ QPair DatabaseQueries::updateMessages(QSqlDatabase db, "contents = :contents, enclosures = :enclosures, feed = :feed " "WHERE id = :id;")); - if (use_transactions && !db.transaction()) { - qCriticalNN << LOGSEC_DB << "Transaction start for message downloader failed:" - << QUOTE_W_SPACE_DOT(query_begin_transaction.lastError().text()); - return updated_messages; - } - QVector msgs_to_insert; for (Message& message : messages) { @@ -1473,20 +1465,8 @@ QPair DatabaseQueries::updateMessages(QSqlDatabase db, qWarningNN << LOGSEC_DB << "Failed to set custom ID for all messages:" << QUOTE_W_SPACE_DOT(db.lastError().text()); } - if (use_transactions && !db.commit()) { - qCriticalNN << LOGSEC_DB - << "Transaction commit for message downloader failed:" << QUOTE_W_SPACE_DOT(db.lastError().text()); - db.rollback(); - - if (ok != nullptr) { - *ok = false; - updated_messages = {0, 0}; - } - } - else { - if (ok != nullptr) { - *ok = true; - } + if (ok != nullptr) { + *ok = true; } return updated_messages; diff --git a/src/librssguard/gui/settings/settingsdatabase.cpp b/src/librssguard/gui/settings/settingsdatabase.cpp index 1b2cacc92..6eb310251 100644 --- a/src/librssguard/gui/settings/settingsdatabase.cpp +++ b/src/librssguard/gui/settings/settingsdatabase.cpp @@ -12,54 +12,70 @@ SettingsDatabase::SettingsDatabase(Settings* settings, QWidget* parent) : SettingsPanel(settings, parent), m_ui(new Ui::SettingsDatabase) { m_ui->setupUi(this); - m_ui->m_lblDataStorageWarning->setHelpText(tr("Note that switching to another data storage type will " - "NOT copy existing your data from currently active data " - "storage to newly selected one."), - true); - m_ui->m_lblMysqlInfo->setHelpText(tr("Note that speed of used MySQL server and latency of used connection " "medium HEAVILY influences the final performance of this application. " "Using slow database connections leads to bad performance when browsing " "feeds or messages."), false); - m_ui->m_lblSqliteInMemoryWarnings->setHelpText(tr("Usage of in-memory working database has several advantages " - "and pitfalls. Make sure that you are familiar with these " - "before you turn this feature on.\n" - "\n" - "Advantages:\n" - " • higher speed for feed/message manipulations " - "(especially with thousands of messages displayed),\n" - " • whole database stored in RAM, thus your hard drive can " - "rest more.\n" - "\n" - "Disadvantages:\n" - " • if application crashes, your changes from last session are lost,\n" - " • application startup and shutdown can take little longer " - "(max. 2 seconds).\n" - "\n" - "Authors of this application are NOT responsible for lost data."), - true); + m_ui->m_lblSqliteInMemoryWarnings + ->setHelpText(tr("Usage of in-memory working database has several advantages " + "and pitfalls. Make sure that you are familiar with these " + "before you turn this feature on.\n" + "\n" + "Advantages:\n" + " • higher speed for feed/message manipulations " + "(especially with thousands of messages displayed),\n" + " • whole database stored in RAM, thus your hard drive can " + "rest more.\n" + "\n" + "Disadvantages:\n" + " • if application crashes, your changes from last session are lost,\n" + " • application startup and shutdown can take little longer " + "(max. 2 seconds).\n" + "\n" + "Authors of this application are NOT responsible for lost data."), + true); m_ui->m_txtMysqlPassword->lineEdit()->setPasswordMode(true); - connect(m_ui->m_cmbDatabaseDriver, static_cast(&QComboBox::currentIndexChanged), this, + connect(m_ui->m_cmbDatabaseDriver, + static_cast(&QComboBox::currentIndexChanged), + this, &SettingsDatabase::dirtifySettings); connect(m_ui->m_checkSqliteUseInMemoryDatabase, &QCheckBox::toggled, this, &SettingsDatabase::dirtifySettings); connect(m_ui->m_txtMysqlDatabase->lineEdit(), &QLineEdit::textChanged, this, &SettingsDatabase::dirtifySettings); connect(m_ui->m_txtMysqlHostname->lineEdit(), &QLineEdit::textChanged, this, &SettingsDatabase::dirtifySettings); connect(m_ui->m_txtMysqlPassword->lineEdit(), &QLineEdit::textChanged, this, &SettingsDatabase::dirtifySettings); - connect(m_ui->m_checkUseTransactions, &QCheckBox::toggled, this, &SettingsDatabase::dirtifySettings); connect(m_ui->m_txtMysqlUsername->lineEdit(), &QLineEdit::textChanged, this, &SettingsDatabase::dirtifySettings); - connect(m_ui->m_spinMysqlPort, static_cast(&QSpinBox::valueChanged), this, &SettingsDatabase::dirtifySettings); - connect(m_ui->m_cmbDatabaseDriver, static_cast(&QComboBox::currentIndexChanged), this, + connect(m_ui->m_spinMysqlPort, + static_cast(&QSpinBox::valueChanged), + this, + &SettingsDatabase::dirtifySettings); + connect(m_ui->m_cmbDatabaseDriver, + static_cast(&QComboBox::currentIndexChanged), + this, &SettingsDatabase::selectSqlBackend); - connect(m_ui->m_txtMysqlUsername->lineEdit(), &BaseLineEdit::textChanged, this, &SettingsDatabase::onMysqlUsernameChanged); - connect(m_ui->m_txtMysqlHostname->lineEdit(), &BaseLineEdit::textChanged, this, &SettingsDatabase::onMysqlHostnameChanged); - connect(m_ui->m_txtMysqlPassword->lineEdit(), &BaseLineEdit::textChanged, this, &SettingsDatabase::onMysqlPasswordChanged); - connect(m_ui->m_txtMysqlDatabase->lineEdit(), &BaseLineEdit::textChanged, this, &SettingsDatabase::onMysqlDatabaseChanged); + connect(m_ui->m_txtMysqlUsername->lineEdit(), + &BaseLineEdit::textChanged, + this, + &SettingsDatabase::onMysqlUsernameChanged); + connect(m_ui->m_txtMysqlHostname->lineEdit(), + &BaseLineEdit::textChanged, + this, + &SettingsDatabase::onMysqlHostnameChanged); + connect(m_ui->m_txtMysqlPassword->lineEdit(), + &BaseLineEdit::textChanged, + this, + &SettingsDatabase::onMysqlPasswordChanged); + connect(m_ui->m_txtMysqlDatabase->lineEdit(), + &BaseLineEdit::textChanged, + this, + &SettingsDatabase::onMysqlDatabaseChanged); connect(m_ui->m_btnMysqlTestSetup, &QPushButton::clicked, this, &SettingsDatabase::mysqlTestConnection); - connect(m_ui->m_cmbDatabaseDriver, static_cast(&QComboBox::currentIndexChanged), this, + connect(m_ui->m_cmbDatabaseDriver, + static_cast(&QComboBox::currentIndexChanged), + this, &SettingsDatabase::requireRestart); connect(m_ui->m_checkSqliteUseInMemoryDatabase, &QCheckBox::toggled, this, &SettingsDatabase::requireRestart); connect(m_ui->m_spinMysqlPort, &QSpinBox::editingFinished, this, &SettingsDatabase::requireRestart); @@ -139,17 +155,14 @@ void SettingsDatabase::selectSqlBackend(int index) { m_ui->m_stackedDatabaseDriver->setCurrentIndex(1); } else { - qWarningNN << LOGSEC_GUI - << "GUI for given database driver '" - << selected_db_driver - << "' is not available."; + qWarningNN << LOGSEC_GUI << "GUI for given database driver '" << selected_db_driver << "' is not available."; } } void SettingsDatabase::loadSettings() { onBeginLoadSettings(); - m_ui->m_checkUseTransactions->setChecked(qApp->settings()->value(GROUP(Database), SETTING(Database::UseTransactions)).toBool()); - m_ui->m_lblMysqlTestResult->setStatus(WidgetWithStatus::StatusType::Information, tr("No connection test triggered so far."), + m_ui->m_lblMysqlTestResult->setStatus(WidgetWithStatus::StatusType::Information, + tr("No connection test triggered so far."), tr("You did not executed any connection test yet.")); // Load SQLite. @@ -158,7 +171,8 @@ void SettingsDatabase::loadSettings() { m_ui->m_cmbDatabaseDriver->addItem(lite_driver->humanDriverType(), lite_driver->qtDriverCode()); // Load in-memory database status. - m_ui->m_checkSqliteUseInMemoryDatabase->setChecked(settings()->value(GROUP(Database), SETTING(Database::UseInMemory)).toBool()); + m_ui->m_checkSqliteUseInMemoryDatabase + ->setChecked(settings()->value(GROUP(Database), SETTING(Database::UseInMemory)).toBool()); auto* mysq_driver = qApp->database()->driverForType(DatabaseDriver::DriverType::MySQL); @@ -176,16 +190,19 @@ void SettingsDatabase::loadSettings() { m_ui->m_txtMysqlUsername->lineEdit()->setPlaceholderText(tr("Username to login with")); m_ui->m_txtMysqlPassword->lineEdit()->setPlaceholderText(tr("Password for your username")); m_ui->m_txtMysqlDatabase->lineEdit()->setPlaceholderText(tr("Working database which you have full access to.")); - m_ui->m_txtMysqlHostname->lineEdit()->setText(settings()->value(GROUP(Database), SETTING(Database::MySQLHostname)).toString()); - m_ui->m_txtMysqlUsername->lineEdit()->setText(settings()->value(GROUP(Database), SETTING(Database::MySQLUsername)).toString()); - m_ui->m_txtMysqlPassword->lineEdit()->setText(settings()->password(GROUP(Database), - SETTING(Database::MySQLPassword)).toString()); - m_ui->m_txtMysqlDatabase->lineEdit()->setText(settings()->value(GROUP(Database), SETTING(Database::MySQLDatabase)).toString()); + m_ui->m_txtMysqlHostname->lineEdit() + ->setText(settings()->value(GROUP(Database), SETTING(Database::MySQLHostname)).toString()); + m_ui->m_txtMysqlUsername->lineEdit() + ->setText(settings()->value(GROUP(Database), SETTING(Database::MySQLUsername)).toString()); + m_ui->m_txtMysqlPassword->lineEdit() + ->setText(settings()->password(GROUP(Database), SETTING(Database::MySQLPassword)).toString()); + m_ui->m_txtMysqlDatabase->lineEdit() + ->setText(settings()->value(GROUP(Database), SETTING(Database::MySQLDatabase)).toString()); m_ui->m_spinMysqlPort->setValue(settings()->value(GROUP(Database), SETTING(Database::MySQLPort)).toInt()); } - int index_current_backend = m_ui->m_cmbDatabaseDriver->findData(settings()->value(GROUP(Database), - SETTING(Database::ActiveDriver)).toString()); + int index_current_backend = + m_ui->m_cmbDatabaseDriver->findData(settings()->value(GROUP(Database), SETTING(Database::ActiveDriver)).toString()); if (index_current_backend >= 0) { m_ui->m_cmbDatabaseDriver->setCurrentIndex(index_current_backend); @@ -201,11 +218,10 @@ void SettingsDatabase::saveSettings() { const bool original_inmemory = settings()->value(GROUP(Database), SETTING(Database::UseInMemory)).toBool(); const bool new_inmemory = m_ui->m_checkSqliteUseInMemoryDatabase->isChecked(); - qApp->settings()->setValue(GROUP(Database), Database::UseTransactions, m_ui->m_checkUseTransactions->isChecked()); - // Save data storage settings. QString original_db_driver = settings()->value(GROUP(Database), SETTING(Database::ActiveDriver)).toString(); - QString selected_db_driver = m_ui->m_cmbDatabaseDriver->itemData(m_ui->m_cmbDatabaseDriver->currentIndex()).toString(); + QString selected_db_driver = + m_ui->m_cmbDatabaseDriver->itemData(m_ui->m_cmbDatabaseDriver->currentIndex()).toString(); // Save SQLite. settings()->setValue(GROUP(Database), Database::UseInMemory, new_inmemory); diff --git a/src/librssguard/gui/settings/settingsdatabase.ui b/src/librssguard/gui/settings/settingsdatabase.ui index 88bb21cad..f63f5e3a5 100644 --- a/src/librssguard/gui/settings/settingsdatabase.ui +++ b/src/librssguard/gui/settings/settingsdatabase.ui @@ -11,20 +11,7 @@ - - - - Note that turning this option ON will make saving of new messages FASTER, but it might rarely cause some issues with messages saving. - - - Use DB transactions when storing downloaded messages - - - - - - - + Database driver @@ -34,10 +21,10 @@ - + - + 0 @@ -204,7 +191,7 @@ - + Qt::Vertical @@ -218,11 +205,6 @@ - m_lblDatabaseDriver - m_cmbDatabaseDriver - m_stackedDatabaseDriver - m_checkUseTransactions - m_lblDataStorageWarning diff --git a/src/librssguard/miscellaneous/settings.cpp b/src/librssguard/miscellaneous/settings.cpp index ea135a409..68431ac98 100644 --- a/src/librssguard/miscellaneous/settings.cpp +++ b/src/librssguard/miscellaneous/settings.cpp @@ -374,9 +374,6 @@ DVALUE(int) Proxy::PortDef = 80; // Database. DKEY Database::ID = "database"; -DKEY Database::UseTransactions = "use_transactions"; -DVALUE(bool) Database::UseTransactionsDef = false; - DKEY Database::UseInMemory = "use_in_memory_db"; DVALUE(bool) Database::UseInMemoryDef = false; diff --git a/src/librssguard/miscellaneous/settings.h b/src/librssguard/miscellaneous/settings.h index f8d25f301..beacc018d 100644 --- a/src/librssguard/miscellaneous/settings.h +++ b/src/librssguard/miscellaneous/settings.h @@ -401,9 +401,6 @@ namespace Proxy { // Database. namespace Database { KEY ID; - KEY UseTransactions; - - VALUE(bool) UseTransactionsDef; KEY UseInMemory; diff --git a/src/librssguard/services/abstract/feed.cpp b/src/librssguard/services/abstract/feed.cpp index 2ce2240b2..56b062cc2 100644 --- a/src/librssguard/services/abstract/feed.cpp +++ b/src/librssguard/services/abstract/feed.cpp @@ -17,8 +17,6 @@ #include "services/abstract/serviceroot.h" #include "services/abstract/unreadnode.h" -#include - Feed::Feed(RootItem* parent) : RootItem(parent), m_source(QString()), m_status(Status::Normal), m_statusString(QString()), m_autoUpdateType(AutoUpdateType::DefaultAutoUpdate), m_autoUpdateInterval(DEFAULT_AUTO_UPDATE_INTERVAL), diff --git a/src/librssguard/services/abstract/importantnode.cpp b/src/librssguard/services/abstract/importantnode.cpp index 9526f96d4..0c1a3d078 100644 --- a/src/librssguard/services/abstract/importantnode.cpp +++ b/src/librssguard/services/abstract/importantnode.cpp @@ -8,8 +8,6 @@ #include "services/abstract/cacheforserviceroot.h" #include "services/abstract/serviceroot.h" -#include - ImportantNode::ImportantNode(RootItem* parent_item) : RootItem(parent_item) { setKind(RootItem::Kind::Important); setId(ID_IMPORTANT); diff --git a/src/librssguard/services/abstract/label.cpp b/src/librssguard/services/abstract/label.cpp index 9fb7e1c83..cd83d52f1 100644 --- a/src/librssguard/services/abstract/label.cpp +++ b/src/librssguard/services/abstract/label.cpp @@ -12,7 +12,6 @@ #include #include -#include Label::Label(const QString& name, const QColor& color, RootItem* parent_item) : Label(parent_item) { setColor(color); diff --git a/src/librssguard/services/abstract/recyclebin.cpp b/src/librssguard/services/abstract/recyclebin.cpp index d80c4ce1a..fdb822c41 100644 --- a/src/librssguard/services/abstract/recyclebin.cpp +++ b/src/librssguard/services/abstract/recyclebin.cpp @@ -9,8 +9,6 @@ #include "services/abstract/cacheforserviceroot.h" #include "services/abstract/serviceroot.h" -#include - RecycleBin::RecycleBin(RootItem* parent_item) : RootItem(parent_item), m_totalCount(0), m_unreadCount(0) { setKind(RootItem::Kind::Bin); setId(ID_RECYCLE_BIN); diff --git a/src/librssguard/services/abstract/serviceroot.cpp b/src/librssguard/services/abstract/serviceroot.cpp index c5e6d541e..57bcf3f85 100644 --- a/src/librssguard/services/abstract/serviceroot.cpp +++ b/src/librssguard/services/abstract/serviceroot.cpp @@ -19,8 +19,6 @@ #include "services/abstract/recyclebin.h" #include "services/abstract/unreadnode.h" -#include - ServiceRoot::ServiceRoot(RootItem* parent) : RootItem(parent), m_recycleBin(new RecycleBin(this)), m_importantNode(new ImportantNode(this)), m_labelsNode(new LabelsNode(this)), m_unreadNode(new UnreadNode(this)), m_accountId(NO_PARENT_CATEGORY), @@ -953,7 +951,6 @@ QPair ServiceRoot::updateMessages(QList& messages, Feed* feed return updated_messages; } - QList items_to_update; bool ok = false; QSqlDatabase database = qApp->database()->driver()->threadSafeConnection(metaObject()->className()); @@ -967,28 +964,22 @@ QPair ServiceRoot::updateMessages(QList& messages, Feed* feed if (recycleBin() != nullptr) { recycleBin()->updateCounts(true); - items_to_update.append(recycleBin()); } if (importantNode() != nullptr) { importantNode()->updateCounts(true); - items_to_update.append(importantNode()); } if (unreadNode() != nullptr) { unreadNode()->updateCounts(true); - items_to_update.append(unreadNode()); } if (labelsNode() != nullptr) { labelsNode()->updateCounts(true); - items_to_update.append(labelsNode()); } } - // Some messages were really added to DB, reload feed in model. - items_to_update.append(feed); - // getParentServiceRoot()->itemChanged(items_to_update); + // NOTE: Do not update model items here. We update only once when all feeds are fetched. return updated_messages; } diff --git a/src/librssguard/services/abstract/unreadnode.cpp b/src/librssguard/services/abstract/unreadnode.cpp index d71be05f5..55d55785e 100644 --- a/src/librssguard/services/abstract/unreadnode.cpp +++ b/src/librssguard/services/abstract/unreadnode.cpp @@ -6,8 +6,6 @@ #include "miscellaneous/application.h" #include "miscellaneous/iconfactory.h" -#include - UnreadNode::UnreadNode(RootItem* parent_item) : RootItem(parent_item) { setKind(RootItem::Kind::Unread); setId(ID_UNREAD); diff --git a/src/librssguard/services/gmail/gmailnetworkfactory.cpp b/src/librssguard/services/gmail/gmailnetworkfactory.cpp index cc0229760..6e1a1ce61 100644 --- a/src/librssguard/services/gmail/gmailnetworkfactory.cpp +++ b/src/librssguard/services/gmail/gmailnetworkfactory.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include GmailNetworkFactory::GmailNetworkFactory(QObject* parent) diff --git a/src/librssguard/services/reddit/redditnetworkfactory.cpp b/src/librssguard/services/reddit/redditnetworkfactory.cpp index 1b3712e4d..4e37b4040 100644 --- a/src/librssguard/services/reddit/redditnetworkfactory.cpp +++ b/src/librssguard/services/reddit/redditnetworkfactory.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include RedditNetworkFactory::RedditNetworkFactory(QObject* parent)