Skip to content

Commit 68be51b

Browse files
author
Martin Rotter
committed
minor fixes to feed updating logic
1 parent 2dcf185 commit 68be51b

File tree

4 files changed

+46
-56
lines changed

4 files changed

+46
-56
lines changed

src/librssguard/database/databasequeries.cpp

Lines changed: 39 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,6 @@ QHash<QString, QStringList> DatabaseQueries::bagsOfMessages(const QSqlDatabase&
10251025
QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
10261026
const QList<Message>& messages,
10271027
Feed* feed,
1028-
const QString& url,
10291028
bool force_update,
10301029
bool* ok) {
10311030
if (messages.isEmpty()) {
@@ -1053,6 +1052,7 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
10531052
// 2) they have same URL AND,
10541053
// 3) they have same AUTHOR AND,
10551054
// 4) they have same TITLE.
1055+
// NOTE: This only applies to messages from standard RSS/ATOM/JSON feeds without ID/GUID.
10561056
query_select_with_url.setForwardOnly(true);
10571057
query_select_with_url.prepare("SELECT id, date_created, is_read, is_important, contents, feed FROM Messages "
10581058
"WHERE feed = :feed AND title = :title AND url = :url AND author = :author AND account_id = :account_id;");
@@ -1096,18 +1096,16 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
10961096
for (Message message : messages) {
10971097
// Check if messages contain relative URLs and if they do, then replace them.
10981098
if (message.m_url.startsWith(QL1S("//"))) {
1099-
// TODO: This probably should be replace with HTTPS or taken scheme from feed's URL?
1100-
message.m_url = QString(URI_SCHEME_HTTP) + message.m_url.mid(2);
1099+
message.m_url = QString(URI_SCHEME_HTTPS) + message.m_url.mid(2);
11011100
}
1102-
else if (message.m_url.startsWith(QL1S("/"))) {
1103-
QString new_message_url = QUrl(url).toString(QUrl::UrlFormattingOption::RemoveUserInfo |
1104-
QUrl::UrlFormattingOption::RemovePath |
1105-
QUrl::UrlFormattingOption::RemoveQuery |
1106-
QUrl::UrlFormattingOption::RemoveFilename |
1107-
QUrl::UrlFormattingOption::StripTrailingSlash);
1101+
else if (QUrl(message.m_url).isRelative()) {
1102+
QUrl base(feed->source());
11081103

1109-
new_message_url += message.m_url;
1110-
message.m_url = new_message_url;
1104+
if (base.isValid()) {
1105+
base = QUrl(base.scheme() + QSL("://") + base.host());
1106+
1107+
message.m_url = base.resolved(message.m_url).toString();
1108+
}
11111109
}
11121110

11131111
int id_existing_message = -1;
@@ -1120,7 +1118,7 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
11201118

11211119
if (message.m_id > 0) {
11221120
// We recognize directly existing message.
1123-
// NOTE: Particular for manual message filter execution.
1121+
// NOTE: Particularly for manual message filter execution.
11241122
query_select_with_id.bindValue(QSL(":id"), message.m_id);
11251123
query_select_with_id.bindValue(QSL(":account_id"), account_id);
11261124

@@ -1139,15 +1137,13 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
11391137
title_existing_message = query_select_with_id.value(5).toString();
11401138

11411139
qDebugNN << LOGSEC_DB
1142-
<< "Message with these attributes is already present in DB and has DB ID '"
1143-
<< id_existing_message
1144-
<< "'.";
1140+
<< "Message with direct DB ID is already present in DB and has DB ID"
1141+
<< QUOTE_W_SPACE_DOT(id_existing_message);
11451142
}
11461143
else if (query_select_with_id.lastError().isValid()) {
11471144
qWarningNN << LOGSEC_DB
1148-
<< "Failed to check for existing message in DB via primary ID: '"
1149-
<< query_select_with_id.lastError().text()
1150-
<< "'.";
1145+
<< "Failed to check for existing message in DB via primary ID:"
1146+
<< QUOTE_W_SPACE_DOT(query_select_with_id.lastError().text());
11511147
}
11521148

11531149
query_select_with_id.finish();
@@ -1181,15 +1177,13 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
11811177
title_existing_message = unnulifyString(message.m_title);
11821178

11831179
qDebugNN << LOGSEC_DB
1184-
<< "Message with these attributes is already present in DB and has DB ID '"
1185-
<< id_existing_message
1186-
<< "'.";
1180+
<< "Message with these attributes is already present in DB and has DB ID"
1181+
<< QUOTE_W_SPACE_DOT(id_existing_message);
11871182
}
11881183
else if (query_select_with_url.lastError().isValid()) {
11891184
qWarningNN << LOGSEC_DB
1190-
<< "Failed to check for existing message in DB via URL: '"
1191-
<< query_select_with_url.lastError().text()
1192-
<< "'.";
1185+
<< "Failed to check for existing message in DB via URL/TITLE/AUTHOR:"
1186+
<< QUOTE_W_SPACE_DOT(query_select_with_url.lastError().text());
11931187
}
11941188

11951189
query_select_with_url.finish();
@@ -1203,9 +1197,9 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
12031197
query_select_with_custom_id.bindValue(QSL(":custom_id"), unnulifyString(message.m_customId));
12041198

12051199
qDebugNN << LOGSEC_DB
1206-
<< "Checking if message with custom ID '"
1207-
<< message.m_customId
1208-
<< "' is present in DB.";
1200+
<< "Checking if message with service-specific custom ID"
1201+
<< QUOTE_W_SPACE(message.m_customId)
1202+
<< "is present in DB.";
12091203

12101204
if (query_select_with_custom_id.exec() && query_select_with_custom_id.next()) {
12111205
id_existing_message = query_select_with_custom_id.value(0).toInt();
@@ -1225,9 +1219,8 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
12251219
}
12261220
else if (query_select_with_custom_id.lastError().isValid()) {
12271221
qWarningNN << LOGSEC_DB
1228-
<< "Failed to check for existing message in DB via ID: '"
1229-
<< query_select_with_custom_id.lastError().text()
1230-
<< "'.";
1222+
<< "Failed to check for existing message in DB via ID:"
1223+
<< QUOTE_W_SPACE_DOT(query_select_with_custom_id.lastError().text());
12311224
}
12321225

12331226
query_select_with_custom_id.finish();
@@ -1240,9 +1233,9 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
12401233
query_select_with_custom_id_for_feed.bindValue(QSL(":custom_id"), unnulifyString(message.m_customId));
12411234

12421235
qDebugNN << LOGSEC_DB
1243-
<< "Checking if message with custom ID '"
1244-
<< message.m_customId
1245-
<< "' is present in DB.";
1236+
<< "Checking if message with feed-specific custom ID"
1237+
<< QUOTE_W_SPACE(message.m_customId)
1238+
<< "is present in DB.";
12461239

12471240
if (query_select_with_custom_id_for_feed.exec() && query_select_with_custom_id_for_feed.next()) {
12481241
id_existing_message = query_select_with_custom_id_for_feed.value(0).toInt();
@@ -1256,15 +1249,13 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
12561249
qDebugNN << LOGSEC_DB
12571250
<< "Message with custom ID"
12581251
<< QUOTE_W_SPACE(message.m_customId)
1259-
<< "is already present in DB and has DB ID '"
1260-
<< id_existing_message
1261-
<< "'.";
1252+
<< "is already present in DB and has DB ID"
1253+
<< QUOTE_W_SPACE_DOT(id_existing_message);
12621254
}
12631255
else if (query_select_with_custom_id_for_feed.lastError().isValid()) {
12641256
qWarningNN << LOGSEC_DB
1265-
<< "Failed to check for existing message in DB via ID: '"
1266-
<< query_select_with_custom_id_for_feed.lastError().text()
1267-
<< "'.";
1257+
<< "Failed to check for existing message in DB via ID:"
1258+
<< QUOTE_W_SPACE_DOT(query_select_with_custom_id_for_feed.lastError().text());
12681259
}
12691260

12701261
query_select_with_custom_id_for_feed.finish();
@@ -1282,7 +1273,7 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
12821273
// 2) FOR NON-SYNCHRONIZED SERVICES (RSS/ATOM/JSON): Message has custom ID/GUID and its title or contents are changed.
12831274
//
12841275
// 3) FOR ALL SERVICES: Message has its date fetched from feed AND its date is different
1285-
// from date in DB and contents is changed.
1276+
// from date in DB or content is changed.
12861277
//
12871278
// 4) FOR ALL SERVICES: Message update is forced, we want to overwrite message as some arbitrary atribute was changed,
12881279
// this particularly happens when manual message filter execution happens.
@@ -1302,7 +1293,7 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
13021293
message.m_contents != contents_existing_message) ||
13031294

13041295
/* 4 */ force_update) {
1305-
// Message exists, it is changed, update it.
1296+
// Message exists and is changed, update it.
13061297
query_update.bindValue(QSL(":title"), unnulifyString(message.m_title));
13071298
query_update.bindValue(QSL(":is_read"), int(message.m_isRead));
13081299
query_update.bindValue(QSL(":is_important"), int(message.m_isImportant));
@@ -1312,13 +1303,13 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
13121303
query_update.bindValue(QSL(":date_created"), message.m_created.toMSecsSinceEpoch());
13131304
query_update.bindValue(QSL(":contents"), unnulifyString(message.m_contents));
13141305
query_update.bindValue(QSL(":enclosures"), Enclosures::encodeEnclosuresToString(message.m_enclosures));
1315-
query_update.bindValue(QSL(":feed"), feed_id_existing_message);
1306+
query_update.bindValue(QSL(":feed"), message.m_feedId);
13161307
query_update.bindValue(QSL(":score"), message.m_score);
13171308
query_update.bindValue(QSL(":id"), id_existing_message);
13181309

13191310
if (query_update.exec()) {
13201311
qDebugNN << LOGSEC_DB
1321-
<< "Updating message with title"
1312+
<< "Overwriting message with title"
13221313
<< QUOTE_W_SPACE(message.m_title)
13231314
<< "URL"
13241315
<< QUOTE_W_SPACE(message.m_url)
@@ -1332,7 +1323,8 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
13321323
}
13331324
else if (query_update.lastError().isValid()) {
13341325
qWarningNN << LOGSEC_DB
1335-
<< "Failed to update message in DB: '" << query_update.lastError().text() << "'.";
1326+
<< "Failed to update message in DB:"
1327+
<< QUOTE_W_SPACE_DOT(query_update.lastError().text());
13361328
}
13371329

13381330
query_update.finish();
@@ -1375,7 +1367,7 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
13751367
}
13761368
else if (query_insert.lastError().isValid()) {
13771369
qWarningNN << LOGSEC_DB
1378-
<< "Failed to insert message to DB:"
1370+
<< "Failed to insert new message to DB:"
13791371
<< QUOTE_W_SPACE(query_insert.lastError().text())
13801372
<< "- message title is"
13811373
<< QUOTE_W_SPACE_DOT(message.m_title);
@@ -1410,9 +1402,8 @@ QPair<int, int> DatabaseQueries::updateMessages(QSqlDatabase db,
14101402
"SET custom_id = id "
14111403
"WHERE custom_id IS NULL OR custom_id = '';").lastError().isValid()) {
14121404
qWarningNN << LOGSEC_DB
1413-
<< "Failed to set custom ID for all messages: '"
1414-
<< db.lastError().text()
1415-
<< "'.";
1405+
<< "Failed to set custom ID for all messages:"
1406+
<< QUOTE_W_SPACE_DOT(db.lastError().text());
14161407
}
14171408

14181409
if (use_transactions && !db.commit()) {

src/librssguard/database/databasequeries.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ class DatabaseQueries {
113113
static void createOverwriteAccount(const QSqlDatabase& db, ServiceRoot* account);
114114

115115
// Returns counts of updated messages <unread, all>.
116-
static QPair<int, int> updateMessages(QSqlDatabase db, const QList<Message>& messages, Feed* feed,
117-
const QString& url, bool force_update, bool* ok = nullptr);
116+
static QPair<int, int> updateMessages(QSqlDatabase db, const QList<Message>& messages,
117+
Feed* feed, bool force_update, bool* ok = nullptr);
118118
static bool deleteAccount(const QSqlDatabase& db, int account_id);
119119
static bool deleteAccountData(const QSqlDatabase& db, int account_id, bool delete_messages_too);
120120
static bool cleanLabelledMessages(const QSqlDatabase& db, bool clean_read_only, Label* label);

src/librssguard/miscellaneous/feedreader.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,8 @@ QList<ServiceEntryPoint*> FeedReader::feedServices() {
7373
void FeedReader::updateFeeds(const QList<Feed*>& feeds) {
7474
if (!qApp->feedUpdateLock()->tryLock()) {
7575
qApp->showGuiMessage(Notification::Event::GeneralEvent,
76-
tr("Cannot fetch articles for all items"),
77-
tr("You cannot fetch new articles for your items "
78-
"because another critical operation is ongoing."),
76+
tr("Cannot fetch articles at this point"),
77+
tr("You cannot fetch new articles now because another critical operation is ongoing."),
7978
QSystemTrayIcon::MessageIcon::Warning,
8079
true);
8180
return;

src/librssguard/services/abstract/feed.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ QPair<int, int> Feed::updateMessages(const QList<Message>& messages, bool force_
193193
QPair<int, int> updated_messages = { 0, 0 };
194194

195195
if (messages.isEmpty()) {
196-
qDebugNN << "No messages to be updated/added in DB.";
196+
qDebugNN << "No messages to be updated/added in DB for feed"
197+
<< QUOTE_W_SPACE_DOT(customId());
197198
return updated_messages;
198199
}
199200

@@ -210,8 +211,7 @@ QPair<int, int> Feed::updateMessages(const QList<Message>& messages, bool force_
210211
qApp->database()->driver()->connection(QSL("feed_upd"));
211212

212213
updated_messages = DatabaseQueries::updateMessages(database, messages,
213-
this,
214-
source(), force_update,
214+
this, force_update,
215215
&ok);
216216

217217
if (updated_messages.first > 0 || updated_messages.second > 0) {

0 commit comments

Comments
 (0)