From 45d7a78684a35932b288fbd107367067401fb781 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Wed, 2 Mar 2022 15:11:17 +0100 Subject: [PATCH] fixup wrong order ids --- src/librssguard/database/databasequeries.cpp | 15 +++++++++------ src/librssguard/services/abstract/rootitem.h | 5 ++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/librssguard/database/databasequeries.cpp b/src/librssguard/database/databasequeries.cpp index 92e06b588..d159aaaf2 100644 --- a/src/librssguard/database/databasequeries.cpp +++ b/src/librssguard/database/databasequeries.cpp @@ -2096,14 +2096,14 @@ bool DatabaseQueries::deleteCategory(const QSqlDatabase& db, int id) { } void DatabaseQueries::fixupOrders(const QSqlDatabase& db) { - QSqlQuery res = db.exec(QSL("SELECT COUNT(*) FROM Accounts WHERE ordr = 0 " + // We first determine if there are same orders assigned to some items + // which have same parent category/acc. + QSqlQuery res = db.exec(QSL("SELECT COUNT(*) FROM Accounts GROUP BY ordr HAVING COUNT(*) > 1 " "UNION ALL " - "SELECT COUNT(*) FROM Categories WHERE ordr = 0 " + "SELECT COUNT(*) FROM Categories GROUP BY account_id, parent_id, ordr HAVING COUNT(*) > 1 " "UNION ALL " - "SELECT COUNT(*) FROM Feeds WHERE ordr = 0;")); - bool should_fixup = false; - - while (res.next() && !(should_fixup = (res.value(0).toInt() > 1))) {} + "SELECT COUNT(*) FROM Feeds GROUP BY account_id, category, ordr HAVING COUNT(*) > 1;")); + bool should_fixup = res.lastError().isValid() || res.size() > 0; if (should_fixup) { // Some orders are messed up, fix. @@ -2117,6 +2117,9 @@ void DatabaseQueries::fixupOrders(const QSqlDatabase& db) { } } } + else { + qDebugNN << LOGSEC_DB << "No fixing of item order is needed."; + } } void DatabaseQueries::moveItemUp(RootItem* item, const QSqlDatabase& db) {} diff --git a/src/librssguard/services/abstract/rootitem.h b/src/librssguard/services/abstract/rootitem.h index e6a7d27b3..63548be3a 100644 --- a/src/librssguard/services/abstract/rootitem.h +++ b/src/librssguard/services/abstract/rootitem.h @@ -205,7 +205,10 @@ class RSSGUARD_DLLSPEC RootItem : public QObject { // which can be manually sorted. Other types like "Label" cannot be // automatically sorted and are always sorted by title. // - // Sort order number cannot be negative. + // Sort order number cannot be negative but order of list of items with same + // parent does not have to form continuous series, for example: + // 0, 1, 2, 3, 4, ... + // 5, 7, 12, 13, 19 int sortOrder() const; void setSortOrder(int sort_order);