From ed39e029cd0707c465296796ffc43f0dc4602af0 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Thu, 19 Aug 2021 07:23:13 +0200 Subject: [PATCH] improved ID fetching right after bulk SQL insert --- .../desktop/com.github.rssguard.appdata.xml | 2 +- src/librssguard/core/messagesproxymodel.cpp | 4 +- src/librssguard/database/databasequeries.cpp | 44 ++++++++++--------- .../services/greader/greadernetwork.cpp | 16 ++++++- 4 files changed, 41 insertions(+), 25 deletions(-) diff --git a/resources/desktop/com.github.rssguard.appdata.xml b/resources/desktop/com.github.rssguard.appdata.xml index 10f8dda57..87150a374 100644 --- a/resources/desktop/com.github.rssguard.appdata.xml +++ b/resources/desktop/com.github.rssguard.appdata.xml @@ -30,7 +30,7 @@ https://martinrotter.github.io/donate/ - + none diff --git a/src/librssguard/core/messagesproxymodel.cpp b/src/librssguard/core/messagesproxymodel.cpp index 35ab79103..f051aeec1 100644 --- a/src/librssguard/core/messagesproxymodel.cpp +++ b/src/librssguard/core/messagesproxymodel.cpp @@ -143,9 +143,9 @@ QModelIndexList MessagesProxyModel::match(const QModelIndex& start, int role, switch (match_type) { #if QT_VERSION >= 0x050F00 // Qt >= 5.15.0 - case Qt::MatchRegularExpression: + case Qt::MatchFlag::MatchRegularExpression: #else - case Qt::MatchRegExp: + case Qt::MatchFlag::MatchRegExp: #endif if (QRegularExpression(entered_text, QRegularExpression::PatternOption::CaseInsensitiveOption | diff --git a/src/librssguard/database/databasequeries.cpp b/src/librssguard/database/databasequeries.cpp index 51a47a7df..3d033510a 100755 --- a/src/librssguard/database/databasequeries.cpp +++ b/src/librssguard/database/databasequeries.cpp @@ -1093,7 +1093,7 @@ QPair DatabaseQueries::updateMessages(QSqlDatabase db, return updated_messages; } - QVector msgs_to_insert; + QVector msgs_to_insert; for (Message& message : messages) { int id_existing_message = -1; @@ -1319,7 +1319,7 @@ QPair DatabaseQueries::updateMessages(QSqlDatabase db, } } else { - msgs_to_insert.append(message); + msgs_to_insert.append(&message); if (!message.m_isRead) { updated_messages.first++; @@ -1336,13 +1336,15 @@ QPair DatabaseQueries::updateMessages(QSqlDatabase db, for (int i = 0; i < msgs_to_insert.size(); i += 1000) { QStringList vals; - auto next_batch = msgs_to_insert.mid(i, 1000); + int batch_length = std::min(1000, msgs_to_insert.size() - i); - for (Message& msg: next_batch) { - if (msg.m_title.isEmpty()) { + for (int l = i; l < (i + batch_length); l++) { + Message* msg = msgs_to_insert[l]; + + if (msg->m_title.isEmpty()) { qCriticalNN << LOGSEC_DB << "Message" - << QUOTE_W_SPACE(msg.m_customId) + << QUOTE_W_SPACE(msg->m_customId) << "will not be inserted to DB because it does not meet DB constraints."; continue; } @@ -1351,18 +1353,18 @@ QPair DatabaseQueries::updateMessages(QSqlDatabase db, "':url', ':author', :score, :date_created, ':contents', ':enclosures', " "':custom_id', ':custom_hash', :account_id)") .replace(QSL(":feed"), unnulifyString(feed_custom_id)) - .replace(QSL(":title"), DatabaseFactory::escapeQuery(unnulifyString(msg.m_title))) - .replace(QSL(":is_read"), QString::number(int(msg.m_isRead))) - .replace(QSL(":is_important"), QString::number(int(msg.m_isImportant))) - .replace(QSL(":is_deleted"), QString::number(int(msg.m_isDeleted))) - .replace(QSL(":url"), DatabaseFactory::escapeQuery(unnulifyString(msg.m_url))) - .replace(QSL(":author"), DatabaseFactory::escapeQuery(unnulifyString(msg.m_author))) - .replace(QSL(":date_created"), QString::number(msg.m_created.toMSecsSinceEpoch())) - .replace(QSL(":contents"), DatabaseFactory::escapeQuery(unnulifyString(msg.m_contents))) - .replace(QSL(":enclosures"), Enclosures::encodeEnclosuresToString(msg.m_enclosures)) - .replace(QSL(":custom_id"), unnulifyString(msg.m_customId)) - .replace(QSL(":custom_hash"), unnulifyString(msg.m_customHash)) - .replace(QSL(":score"), QString::number(msg.m_score)) + .replace(QSL(":title"), DatabaseFactory::escapeQuery(unnulifyString(msg->m_title))) + .replace(QSL(":is_read"), QString::number(int(msg->m_isRead))) + .replace(QSL(":is_important"), QString::number(int(msg->m_isImportant))) + .replace(QSL(":is_deleted"), QString::number(int(msg->m_isDeleted))) + .replace(QSL(":url"), DatabaseFactory::escapeQuery(unnulifyString(msg->m_url))) + .replace(QSL(":author"), DatabaseFactory::escapeQuery(unnulifyString(msg->m_author))) + .replace(QSL(":date_created"), QString::number(msg->m_created.toMSecsSinceEpoch())) + .replace(QSL(":contents"), DatabaseFactory::escapeQuery(unnulifyString(msg->m_contents))) + .replace(QSL(":enclosures"), Enclosures::encodeEnclosuresToString(msg->m_enclosures)) + .replace(QSL(":custom_id"), unnulifyString(msg->m_customId)) + .replace(QSL(":custom_hash"), unnulifyString(msg->m_customHash)) + .replace(QSL(":score"), QString::number(msg->m_score)) .replace(QSL(":account_id"), QString::number(account_id))); } @@ -1388,8 +1390,10 @@ QPair DatabaseQueries::updateMessages(QSqlDatabase db, // https://mariadb.com/kb/en/auto_increment int last_msg_id = bulk_query.lastInsertId().toInt(); - for (int j = next_batch.size() - 1, k = 0; j >= 0; j--, k++) { - next_batch[j].m_id = last_msg_id - k; + for (int l = i, c = 1; l < (i + batch_length); l++, c++) { + Message* msg = msgs_to_insert[l]; + + msg->m_id = last_msg_id - batch_length + c; } } } diff --git a/src/librssguard/services/greader/greadernetwork.cpp b/src/librssguard/services/greader/greadernetwork.cpp index b7a791c31..c3e2d1d74 100755 --- a/src/librssguard/services/greader/greadernetwork.cpp +++ b/src/librssguard/services/greader/greadernetwork.cpp @@ -376,7 +376,13 @@ QStringList GreaderNetwork::itemIds(const QString& stream_id, bool unread_only, } if (newer_than.isValid()) { - full_url += QSL("&ot=%1").arg(QDateTime(newer_than).toSecsSinceEpoch()); + full_url += QSL("&ot=%1").arg( +#if QT_VERSION < 0x050E00 // Qt < 5.14.0 + QDateTime(newer_than) +#else + newer_than.startOfDay() +#endif + .toSecsSinceEpoch()); } QByteArray output_stream; @@ -505,7 +511,13 @@ QList GreaderNetwork::streamContents(ServiceRoot* root, const QString& } if (m_newerThanFilter.isValid()) { - full_url += QSL("&ot=%1").arg(QDateTime(m_newerThanFilter).toSecsSinceEpoch()); + full_url += QSL("&ot=%1").arg( +#if QT_VERSION < 0x050E00 // Qt < 5.14.0 + QDateTime(m_newerThanFilter) +#else + m_newerThanFilter.startOfDay() +#endif + .toSecsSinceEpoch()); } QByteArray output_stream;