Tweaked message update method + SQL scripts.
This commit is contained in:
parent
ee04eb87c7
commit
3c8b0441b5
4 changed files with 19 additions and 9 deletions
|
@ -10,14 +10,14 @@ CREATE TABLE IF NOT EXISTS OwnCloudAccounts (
|
||||||
-- !
|
-- !
|
||||||
UPDATE Categories
|
UPDATE Categories
|
||||||
SET custom_id = (SELECT id FROM Categories t WHERE t.id = Categories.id)
|
SET custom_id = (SELECT id FROM Categories t WHERE t.id = Categories.id)
|
||||||
WHERE Categories.custom_id IS NULL;
|
WHERE Categories.custom_id IS NULL OR Categories.custom_id = '';
|
||||||
-- !
|
-- !
|
||||||
UPDATE Feeds
|
UPDATE Feeds
|
||||||
SET custom_id = (SELECT id FROM Feeds t WHERE t.id = Feeds.id)
|
SET custom_id = (SELECT id FROM Feeds t WHERE t.id = Feeds.id)
|
||||||
WHERE Feeds.custom_id IS NULL;
|
WHERE Feeds.custom_id IS NULL OR Feeds.custom_id = '';
|
||||||
-- !
|
-- !
|
||||||
UPDATE Messages
|
UPDATE Messages
|
||||||
SET custom_id = (SELECT id FROM Messages t WHERE t.id = Messages.id)
|
SET custom_id = (SELECT id FROM Messages t WHERE t.id = Messages.id)
|
||||||
WHERE Messages.custom_id IS NULL;
|
WHERE Messages.custom_id IS NULL OR Messages.custom_id = '';
|
||||||
-- !
|
-- !
|
||||||
UPDATE Information SET inf_value = '5' WHERE inf_key = 'schema_version';
|
UPDATE Information SET inf_value = '5' WHERE inf_key = 'schema_version';
|
|
@ -10,14 +10,14 @@ CREATE TABLE IF NOT EXISTS OwnCloudAccounts (
|
||||||
-- !
|
-- !
|
||||||
UPDATE Categories
|
UPDATE Categories
|
||||||
SET custom_id = (SELECT id FROM Categories t WHERE t.id = Categories.id)
|
SET custom_id = (SELECT id FROM Categories t WHERE t.id = Categories.id)
|
||||||
WHERE Categories.custom_id IS NULL;
|
WHERE Categories.custom_id IS NULL OR Categories.custom_id = '';
|
||||||
-- !
|
-- !
|
||||||
UPDATE Feeds
|
UPDATE Feeds
|
||||||
SET custom_id = (SELECT id FROM Feeds t WHERE t.id = Feeds.id)
|
SET custom_id = (SELECT id FROM Feeds t WHERE t.id = Feeds.id)
|
||||||
WHERE Feeds.custom_id IS NULL;
|
WHERE Feeds.custom_id IS NULL OR Feeds.custom_id = '';
|
||||||
-- !
|
-- !
|
||||||
UPDATE Messages
|
UPDATE Messages
|
||||||
SET custom_id = (SELECT id FROM Messages t WHERE t.id = Messages.id)
|
SET custom_id = (SELECT id FROM Messages t WHERE t.id = Messages.id)
|
||||||
WHERE Messages.custom_id IS NULL;
|
WHERE Messages.custom_id IS NULL OR Messages.custom_id = '';
|
||||||
-- !
|
-- !
|
||||||
UPDATE Information SET inf_value = '5' WHERE inf_key = 'schema_version';
|
UPDATE Information SET inf_value = '5' WHERE inf_key = 'schema_version';
|
|
@ -206,6 +206,7 @@ int Feed::updateMessages(const QList<Message> &messages) {
|
||||||
|
|
||||||
if (message.m_customId.isEmpty()) {
|
if (message.m_customId.isEmpty()) {
|
||||||
// We need to recognize existing messages according URL & AUTHOR.
|
// We need to recognize existing messages according URL & AUTHOR.
|
||||||
|
// NOTE: This concerns messages from standard account.
|
||||||
query_select_with_url.bindValue(QSL(":feed"), custom_id);
|
query_select_with_url.bindValue(QSL(":feed"), custom_id);
|
||||||
query_select_with_url.bindValue(QSL(":url"), message.m_url);
|
query_select_with_url.bindValue(QSL(":url"), message.m_url);
|
||||||
query_select_with_url.bindValue(QSL(":author"), message.m_author);
|
query_select_with_url.bindValue(QSL(":author"), message.m_author);
|
||||||
|
@ -222,6 +223,7 @@ int Feed::updateMessages(const QList<Message> &messages) {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// We can recognize existing messages via their custom ID.
|
// We can recognize existing messages via their custom ID.
|
||||||
|
// NOTE: This concerns messages from custom accounts, like TT-RSS or ownCloud News.
|
||||||
query_select_with_id.bindValue(QSL(":account_id"), account_id);
|
query_select_with_id.bindValue(QSL(":account_id"), account_id);
|
||||||
query_select_with_id.bindValue(QSL(":custom_id"), message.m_customId);
|
query_select_with_id.bindValue(QSL(":custom_id"), message.m_customId);
|
||||||
|
|
||||||
|
@ -243,7 +245,7 @@ int Feed::updateMessages(const QList<Message> &messages) {
|
||||||
// 1) Message has custom ID AND (its date OR read status OR starred status are changed).
|
// 1) Message has custom ID AND (its date OR read status OR starred status are changed).
|
||||||
// 2) Message has its date fetched from feed AND its date is different from date in DB.
|
// 2) Message has its date fetched from feed AND its date is different from date in DB.
|
||||||
if (/* 1 */ (!message.m_customId.isEmpty() && (message.m_created.toMSecsSinceEpoch() != date_existing_message || message.m_isRead != is_read_existing_message || message.m_isImportant != is_important_existing_message)) ||
|
if (/* 1 */ (!message.m_customId.isEmpty() && (message.m_created.toMSecsSinceEpoch() != date_existing_message || message.m_isRead != is_read_existing_message || message.m_isImportant != is_important_existing_message)) ||
|
||||||
/* 2 */ (message.m_createdFromFeed && message.m_created.toMSecsSinceEpoch() > date_existing_message)) {
|
/* 2 */ (message.m_createdFromFeed && message.m_created.toMSecsSinceEpoch() != date_existing_message)) {
|
||||||
// Message exists, it is changed, update it.
|
// Message exists, it is changed, update it.
|
||||||
query_update.bindValue(QSL(":title"), message.m_title);
|
query_update.bindValue(QSL(":title"), message.m_title);
|
||||||
query_update.bindValue(QSL(":is_read"), (int) message.m_isRead);
|
query_update.bindValue(QSL(":is_read"), (int) message.m_isRead);
|
||||||
|
@ -288,6 +290,14 @@ int Feed::updateMessages(const QList<Message> &messages) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Now, fixup custom IDS for messages which initially did not have them,
|
||||||
|
// just to keep the data consistent.
|
||||||
|
if (database.exec("UPDATE Messages "
|
||||||
|
"SET custom_id = (SELECT id FROM Messages t WHERE t.id = Messages.id) "
|
||||||
|
"WHERE Messages.custom_id IS NULL OR Messages.custom_id = '';").lastError().isValid()) {
|
||||||
|
qWarning("Failed to set custom ID for all messages.");
|
||||||
|
}
|
||||||
|
|
||||||
if (!database.commit()) {
|
if (!database.commit()) {
|
||||||
database.rollback();
|
database.rollback();
|
||||||
qDebug("Transaction commit for message downloader failed.");
|
qDebug("Transaction commit for message downloader failed.");
|
||||||
|
@ -305,7 +315,7 @@ int Feed::updateMessages(const QList<Message> &messages) {
|
||||||
updateCounts(true);
|
updateCounts(true);
|
||||||
items_to_update.append(this);
|
items_to_update.append(this);
|
||||||
|
|
||||||
if (getParentServiceRoot()->recycleBin() != NULL && anything_updated ) {
|
if (getParentServiceRoot()->recycleBin() != NULL && anything_updated) {
|
||||||
getParentServiceRoot()->recycleBin()->updateCounts(true);
|
getParentServiceRoot()->recycleBin()->updateCounts(true);
|
||||||
items_to_update.append(getParentServiceRoot()->recycleBin());
|
items_to_update.append(getParentServiceRoot()->recycleBin());
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ class Feed : public RootItem {
|
||||||
enum Status {
|
enum Status {
|
||||||
Normal = 0,
|
Normal = 0,
|
||||||
NewMessages = 1,
|
NewMessages = 1,
|
||||||
Error = 2,
|
Error = 2,
|
||||||
ParsingError = 3,
|
ParsingError = 3,
|
||||||
OtherError = 4
|
OtherError = 4
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue