Make some more DB fixes and fix red error color.
This commit is contained in:
parent
ec4eb2e561
commit
755eda6eff
5 changed files with 49 additions and 36 deletions
|
@ -179,20 +179,20 @@ bool DatabaseQueries::purgeRecycleBin(QSqlDatabase db) {
|
||||||
return q.exec();
|
return q.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<int,int> DatabaseQueries::getMessageCountsForCategory(QSqlDatabase db, int custom_id, int account_id,
|
QMap<int,QPair<int,int> > DatabaseQueries::getMessageCountsForCategory(QSqlDatabase db, int custom_id, int account_id,
|
||||||
bool including_total_counts, bool *ok) {
|
bool including_total_counts, bool *ok) {
|
||||||
QMap<int,int> counts;
|
QMap<int, QPair<int,int> > counts;
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
q.setForwardOnly(true);
|
q.setForwardOnly(true);
|
||||||
|
|
||||||
if (including_total_counts) {
|
if (including_total_counts) {
|
||||||
q.prepare("SELECT feed, count(*) FROM Messages "
|
q.prepare("SELECT feed, sum((is_read + 1) % 2), count(*) FROM Messages "
|
||||||
"WHERE feed IN (SELECT custom_id FROM Feeds WHERE category = :category AND account_id = :account_id) AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id "
|
"WHERE feed IN (SELECT custom_id FROM Feeds WHERE category = :category AND account_id = :account_id) AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id "
|
||||||
"GROUP BY feed;");
|
"GROUP BY feed;");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
q.prepare("SELECT feed, count(*) FROM Messages "
|
q.prepare("SELECT feed, sum((is_read + 1) % 2) FROM Messages "
|
||||||
"WHERE feed IN (SELECT custom_id FROM Feeds WHERE category = :category AND account_id = :account_id) AND is_deleted = 0 AND is_pdeleted = 0 AND is_read = 0 AND account_id = :account_id "
|
"WHERE feed IN (SELECT custom_id FROM Feeds WHERE category = :category AND account_id = :account_id) AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id "
|
||||||
"GROUP BY feed;");
|
"GROUP BY feed;");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,9 +202,16 @@ QMap<int,int> DatabaseQueries::getMessageCountsForCategory(QSqlDatabase db, int
|
||||||
if (q.exec()) {
|
if (q.exec()) {
|
||||||
while (q.next()) {
|
while (q.next()) {
|
||||||
int feed_id = q.value(0).toInt();
|
int feed_id = q.value(0).toInt();
|
||||||
int new_count = q.value(1).toInt();
|
int unread_count = q.value(1).toInt();
|
||||||
|
|
||||||
counts.insert(feed_id, new_count);
|
if (including_total_counts) {
|
||||||
|
int total_count = q.value(2).toInt();
|
||||||
|
|
||||||
|
counts.insert(feed_id, QPair<int,int>(unread_count, total_count));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
counts.insert(feed_id, QPair<int,int>(unread_count, 0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ok != NULL) {
|
if (ok != NULL) {
|
||||||
|
@ -220,20 +227,20 @@ QMap<int,int> DatabaseQueries::getMessageCountsForCategory(QSqlDatabase db, int
|
||||||
return counts;
|
return counts;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<int, QPair<int,int> > DatabaseQueries::getMessageCountsForAccount(QSqlDatabase db, int account_id,
|
QMap<int,QPair<int,int> > DatabaseQueries::getMessageCountsForAccount(QSqlDatabase db, int account_id,
|
||||||
bool including_total_counts, bool *ok) {
|
bool including_total_counts, bool *ok) {
|
||||||
QMap<int, QPair<int,int> > counts;
|
QMap<int,QPair<int,int> > counts;
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
q.setForwardOnly(true);
|
q.setForwardOnly(true);
|
||||||
|
|
||||||
if (including_total_counts) {
|
if (including_total_counts) {
|
||||||
q.prepare("SELECT feed, sum((is_read + 1) % 2), count(*) FROM Messages "
|
q.prepare("SELECT feed, sum((is_read + 1) % 2), count(*) FROM Messages "
|
||||||
"WHERE feed IN (SELECT custom_id FROM Feeds WHERE account_id = :account_id) AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id "
|
"WHERE is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id "
|
||||||
"GROUP BY feed;");
|
"GROUP BY feed;");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
q.prepare("SELECT feed, sum((is_read + 1) % 2) FROM Messages "
|
q.prepare("SELECT feed, sum((is_read + 1) % 2) FROM Messages "
|
||||||
"WHERE feed IN (SELECT custom_id FROM Feeds WHERE account_id = :account_id) AND is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id "
|
"WHERE is_deleted = 0 AND is_pdeleted = 0 AND account_id = :account_id "
|
||||||
"GROUP BY feed;");
|
"GROUP BY feed;");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,10 +41,10 @@ class DatabaseQueries {
|
||||||
static bool purgeReadMessages(QSqlDatabase db);
|
static bool purgeReadMessages(QSqlDatabase db);
|
||||||
static bool purgeOldMessages(QSqlDatabase db, int older_than_days);
|
static bool purgeOldMessages(QSqlDatabase db, int older_than_days);
|
||||||
static bool purgeRecycleBin(QSqlDatabase db);
|
static bool purgeRecycleBin(QSqlDatabase db);
|
||||||
static QMap<int,int> getMessageCountsForCategory(QSqlDatabase db, int custom_id, int account_id,
|
static QMap<int,QPair<int,int> > getMessageCountsForCategory(QSqlDatabase db, int custom_id, int account_id,
|
||||||
bool including_total_counts, bool *ok = NULL);
|
bool including_total_counts, bool *ok = NULL);
|
||||||
static QMap<int,QPair<int,int> > getMessageCountsForAccount(QSqlDatabase db, int account_id,
|
static QMap<int,QPair<int,int> > getMessageCountsForAccount(QSqlDatabase db, int account_id,
|
||||||
bool including_total_counts, bool *ok = NULL);
|
bool including_total_counts, bool *ok = NULL);
|
||||||
static int getMessageCountsForFeed(QSqlDatabase db, int feed_custom_id, int account_id,
|
static int getMessageCountsForFeed(QSqlDatabase db, int feed_custom_id, int account_id,
|
||||||
bool including_total_counts, bool *ok = NULL);
|
bool including_total_counts, bool *ok = NULL);
|
||||||
static int getMessageCountsForBin(QSqlDatabase db, int account_id, bool including_total_counts, bool *ok = NULL);
|
static int getMessageCountsForBin(QSqlDatabase db, int account_id, bool including_total_counts, bool *ok = NULL);
|
||||||
|
|
|
@ -48,24 +48,18 @@ void Category::updateCounts(bool including_total_count) {
|
||||||
|
|
||||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
|
||||||
bool ok;
|
bool ok;
|
||||||
|
QMap<int,QPair<int,int> > counts = DatabaseQueries::getMessageCountsForCategory(database, customId(), getParentServiceRoot()->accountId(),
|
||||||
if (including_total_count) {
|
including_total_count, &ok);
|
||||||
QMap<int,int> counts = DatabaseQueries::getMessageCountsForCategory(database, customId(), getParentServiceRoot()->accountId(),
|
|
||||||
including_total_count, &ok);
|
|
||||||
|
|
||||||
if (ok) {
|
|
||||||
foreach (Feed *feed, feeds) {
|
|
||||||
feed->setCountOfAllMessages(counts.value(feed->customId()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QMap<int,int> counts = DatabaseQueries::getMessageCountsForCategory(database, customId(), getParentServiceRoot()->accountId(),
|
|
||||||
false, &ok);
|
|
||||||
|
|
||||||
if (ok) {
|
if (ok) {
|
||||||
foreach (Feed *feed, feeds) {
|
foreach (Feed *feed, feeds) {
|
||||||
feed->setCountOfUnreadMessages(counts.value(feed->customId()));
|
if (counts.contains(feed->customId())) {
|
||||||
|
feed->setCountOfUnreadMessages(counts.value(feed->customId()).first);
|
||||||
|
|
||||||
|
if (including_total_count) {
|
||||||
|
feed->setCountOfAllMessages(counts.value(feed->customId()).second);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,8 @@ QVariant Feed::data(int column, int role) const {
|
||||||
return QColor(Qt::blue);
|
return QColor(Qt::blue);
|
||||||
|
|
||||||
case Error:
|
case Error:
|
||||||
|
case ParsingError:
|
||||||
|
case OtherError:
|
||||||
return QColor(Qt::red);
|
return QColor(Qt::red);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -84,7 +86,13 @@ void Feed::setCountOfUnreadMessages(int count_unread_messages) {
|
||||||
|
|
||||||
int Feed::update() {
|
int Feed::update() {
|
||||||
QList<Message> msgs = obtainNewMessages();
|
QList<Message> msgs = obtainNewMessages();
|
||||||
return updateMessages(msgs);
|
|
||||||
|
if (msgs.size() > 0) {
|
||||||
|
return updateMessages(msgs);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Feed::setAutoUpdateInitialInterval(int auto_update_interval) {
|
void Feed::setAutoUpdateInitialInterval(int auto_update_interval) {
|
||||||
|
|
|
@ -95,11 +95,15 @@ void ServiceRoot::updateCounts(bool including_total_count) {
|
||||||
bool ok;
|
bool ok;
|
||||||
QMap<int,QPair<int,int> > counts = DatabaseQueries::getMessageCountsForAccount(database, accountId(), including_total_count, &ok);
|
QMap<int,QPair<int,int> > counts = DatabaseQueries::getMessageCountsForAccount(database, accountId(), including_total_count, &ok);
|
||||||
|
|
||||||
foreach (Feed *feed, feeds) {
|
if (ok) {
|
||||||
feed->setCountOfUnreadMessages(counts.value(feed->customId()).first);
|
foreach (Feed *feed, feeds) {
|
||||||
|
if (counts.contains(feed->customId())) {
|
||||||
|
feed->setCountOfUnreadMessages(counts.value(feed->customId()).first);
|
||||||
|
|
||||||
if (including_total_count) {
|
if (including_total_count) {
|
||||||
feed->setCountOfAllMessages(counts.value(feed->customId()).second);
|
feed->setCountOfAllMessages(counts.value(feed->customId()).second);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue