Couple of debug outputs fixed/added. Cleaned up logic for setting feed state according to errors in network/auth/etc.

This commit is contained in:
Martin Rotter 2017-11-10 07:22:48 +01:00
parent 98c5ae234d
commit a93c14ddc5
11 changed files with 64 additions and 28 deletions

@ -1 +1 @@
Subproject commit ae7084718c41afc01919779e58cd449e0eebd401 Subproject commit 4a01edaec7d67d3b2ae81aeea2a3c876216fbab8

View File

@ -34,20 +34,14 @@ bool FeedDownloader::isUpdateRunning() const {
} }
void FeedDownloader::updateAvailableFeeds() { void FeedDownloader::updateAvailableFeeds() {
QList<CacheForServiceRoot*> caches;
foreach (const Feed* feed, m_feeds) { foreach (const Feed* feed, m_feeds) {
CacheForServiceRoot* cache = dynamic_cast<CacheForServiceRoot*>(feed->getParentServiceRoot()); CacheForServiceRoot* cache = dynamic_cast<CacheForServiceRoot*>(feed->getParentServiceRoot());
if (cache != nullptr && !caches.contains(cache)) { if (cache != nullptr) {
caches.append(cache); qDebug("Saving cache for feed with DB ID %d and title '%s'.", feed->id(), qPrintable(feed->title()));
}
}
// Now, we synchronously save cached data.
foreach (CacheForServiceRoot* cache, caches) {
cache->saveAllCachedData(false); cache->saveAllCachedData(false);
} }
}
while (!m_feeds.isEmpty()) { while (!m_feeds.isEmpty()) {
connect(m_feeds.first(), &Feed::messagesObtained, this, &FeedDownloader::oneFeedUpdateFinished, connect(m_feeds.first(), &Feed::messagesObtained, this, &FeedDownloader::oneFeedUpdateFinished,
@ -58,6 +52,8 @@ void FeedDownloader::updateAvailableFeeds() {
m_feedsUpdating++; m_feedsUpdating++;
} }
else { else {
qCritical("User wanted to update some feeds but all working threads are occupied.");
// We want to start update of some feeds but all working threads are occupied. // We want to start update of some feeds but all working threads are occupied.
break; break;
} }
@ -103,9 +99,10 @@ void FeedDownloader::oneFeedUpdateFinished(const QList<Message>& messages, bool
updateAvailableFeeds(); updateAvailableFeeds();
// Now make sure, that messages are actually stored to SQL in a locked state. // Now make sure, that messages are actually stored to SQL in a locked state.
qDebug().nospace() << "Saving messages of feed " qDebug().nospace() << "Saving messages of feed ID "
<< feed->customId() << " in thread: \'" << feed->customId() << " URL: " << feed->url() << " title: " << feed->title() << " in thread: \'"
<< QThread::currentThreadId() << "\'."; << QThread::currentThreadId() << "\'.";
int updated_messages = feed->updateMessages(messages, error_during_obtaining); int updated_messages = feed->updateMessages(messages, error_during_obtaining);
qDebug("%d messages for feed %s stored in DB.", updated_messages, qPrintable(feed->customId())); qDebug("%d messages for feed %s stored in DB.", updated_messages, qPrintable(feed->customId()));

View File

@ -67,6 +67,7 @@ int main(int argc, char* argv[]) {
QDir::separator() + QL1S("rssguard.log")); QDir::separator() + QL1S("rssguard.log"));
} }
qDebug("Starting %s.", qPrintable(QSL(APP_LONG_NAME)));
qDebug("Instantiated Application class."); qDebug("Instantiated Application class.");
// Check if another instance is running. // Check if another instance is running.

View File

@ -522,6 +522,9 @@ int DatabaseQueries::updateMessages(QSqlDatabase db,
query_select_with_url.bindValue(QSL(":author"), message.m_author); query_select_with_url.bindValue(QSL(":author"), message.m_author);
query_select_with_url.bindValue(QSL(":account_id"), account_id); query_select_with_url.bindValue(QSL(":account_id"), account_id);
qDebug("Checking if message with title '%s', url '%s' and author '%s' is present in DB.",
qPrintable(message.m_title), qPrintable(message.m_url), qPrintable(message.m_author));
if (query_select_with_url.exec() && query_select_with_url.next()) { if (query_select_with_url.exec() && query_select_with_url.next()) {
id_existing_message = query_select_with_url.value(0).toInt(); id_existing_message = query_select_with_url.value(0).toInt();
date_existing_message = query_select_with_url.value(1).value<qint64>(); date_existing_message = query_select_with_url.value(1).value<qint64>();
@ -529,6 +532,9 @@ int DatabaseQueries::updateMessages(QSqlDatabase db,
is_important_existing_message = query_select_with_url.value(3).toBool(); is_important_existing_message = query_select_with_url.value(3).toBool();
contents_existing_message = query_select_with_url.value(4).toString(); contents_existing_message = query_select_with_url.value(4).toString();
feed_id_existing_message = query_select_with_url.value(5).toString(); feed_id_existing_message = query_select_with_url.value(5).toString();
qDebug("Message with these attributes is already present in DB and has DB ID %d.",
qPrintable(message.m_customId), id_existing_message);
} }
else if (query_select_with_url.lastError().isValid()) { else if (query_select_with_url.lastError().isValid()) {
qWarning("Failed to check for existing message in DB via URL: '%s'.", qPrintable(query_select_with_url.lastError().text())); qWarning("Failed to check for existing message in DB via URL: '%s'.", qPrintable(query_select_with_url.lastError().text()));
@ -542,6 +548,8 @@ int DatabaseQueries::updateMessages(QSqlDatabase db,
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);
qDebug("Checking if message with custom ID %s is present in DB.", qPrintable(message.m_customId));
if (query_select_with_id.exec() && query_select_with_id.next()) { if (query_select_with_id.exec() && query_select_with_id.next()) {
id_existing_message = query_select_with_id.value(0).toInt(); id_existing_message = query_select_with_id.value(0).toInt();
date_existing_message = query_select_with_id.value(1).value<qint64>(); date_existing_message = query_select_with_id.value(1).value<qint64>();
@ -549,6 +557,9 @@ int DatabaseQueries::updateMessages(QSqlDatabase db,
is_important_existing_message = query_select_with_id.value(3).toBool(); is_important_existing_message = query_select_with_id.value(3).toBool();
contents_existing_message = query_select_with_id.value(4).toString(); contents_existing_message = query_select_with_id.value(4).toString();
feed_id_existing_message = query_select_with_id.value(5).toString(); feed_id_existing_message = query_select_with_id.value(5).toString();
qDebug("Message with custom ID %s is already present in DB and has DB ID %d.",
qPrintable(message.m_customId), id_existing_message);
} }
else if (query_select_with_id.lastError().isValid()) { else if (query_select_with_id.lastError().isValid()) {
qDebug("Failed to check for existing message in DB via ID: '%s'.", qPrintable(query_select_with_id.lastError().text())); qDebug("Failed to check for existing message in DB via ID: '%s'.", qPrintable(query_select_with_id.lastError().text()));
@ -584,15 +595,18 @@ int DatabaseQueries::updateMessages(QSqlDatabase db,
query_update.bindValue(QSL(":id"), id_existing_message); query_update.bindValue(QSL(":id"), id_existing_message);
*any_message_changed = true; *any_message_changed = true;
if (query_update.exec() && !message.m_isRead) { if (query_update.exec()) {
qDebug("Updating message with title '%s' url '%s' in DB.", qPrintable(message.m_title), qPrintable(message.m_url));
if (!message.m_isRead) {
updated_messages++; updated_messages++;
} }
}
else if (query_update.lastError().isValid()) { else if (query_update.lastError().isValid()) {
qWarning("Failed to update message in DB: '%s'.", qPrintable(query_update.lastError().text())); qWarning("Failed to update message in DB: '%s'.", qPrintable(query_update.lastError().text()));
} }
query_update.finish(); query_update.finish();
qDebug("Updating message '%s' in DB.", qPrintable(message.m_title));
} }
} }
else { else {
@ -613,7 +627,7 @@ int DatabaseQueries::updateMessages(QSqlDatabase db,
if (query_insert.exec() && query_insert.numRowsAffected() == 1) { if (query_insert.exec() && query_insert.numRowsAffected() == 1) {
updated_messages++; updated_messages++;
//qDebug("Added new message '%s' to DB.", qPrintable(message.m_title)); qDebug("Adding new message with title '%s' url '%s' to DB.", qPrintable(message.m_title), qPrintable(message.m_url));
} }
else if (query_insert.lastError().isValid()) { else if (query_insert.lastError().isValid()) {
qWarning("Failed to insert message to DB: '%s' - message title is '%s'.", qWarning("Failed to insert message to DB: '%s' - message title is '%s'.",

View File

@ -69,6 +69,8 @@ void FeedReader::updateFeeds(const QList<Feed*>& feeds) {
} }
if (m_feedDownloader == nullptr) { if (m_feedDownloader == nullptr) {
qDebug("Creating FeedDownloader singleton.");
m_feedDownloader = new FeedDownloader(); m_feedDownloader = new FeedDownloader();
m_feedDownloaderThread = new QThread(); m_feedDownloaderThread = new QThread();

View File

@ -163,15 +163,16 @@ void Feed::updateCounts(bool including_total_count) {
} }
void Feed::run() { void Feed::run() {
qDebug().nospace() << "Downloading new messages for feed " qDebug().nospace() << "Downloading new messages for feed ID "
<< customId() << " in thread: \'" << customId() << " URL: " << url() << " title: " << title() << " in thread: \'"
<< QThread::currentThreadId() << "\'."; << QThread::currentThreadId() << "\'.";
bool error_during_obtaining = false; bool error_during_obtaining = false;
QList<Message> msgs = obtainNewMessages(&error_during_obtaining); QList<Message> msgs = obtainNewMessages(&error_during_obtaining);
qDebug().nospace() << "Downloaded " << msgs.size() << " messages for feed "
<< customId() << " in thread: \'" qDebug().nospace() << "Downloaded " << msgs.size() << " messages for feed ID "
<< customId() << " URL: " << url() << " title: " << title() << " in thread: \'"
<< QThread::currentThreadId() << "\'."; << QThread::currentThreadId() << "\'.";
// Now, do some general operations on messages (tweak encoding etc.). // Now, do some general operations on messages (tweak encoding etc.).
@ -229,6 +230,9 @@ int Feed::updateMessages(const QList<Message>& messages, bool error_during_obtai
updated_messages = DatabaseQueries::updateMessages(database, messages, custom_id, account_id, url(), &anything_updated, &ok); updated_messages = DatabaseQueries::updateMessages(database, messages, custom_id, account_id, url(), &anything_updated, &ok);
} }
else {
qWarning("There are no messages for update.");
}
if (ok) { if (ok) {
setStatus(updated_messages > 0 ? NewMessages : Normal); setStatus(updated_messages > 0 ? NewMessages : Normal);
@ -244,8 +248,12 @@ int Feed::updateMessages(const QList<Message>& messages, bool error_during_obtai
qCritical("There is indication that there was error during messages obtaining."); qCritical("There is indication that there was error during messages obtaining.");
} }
if (ok && !messages.isEmpty()) {
// Some messages were really added to DB, reload feed in model.
items_to_update.append(this); items_to_update.append(this);
getParentServiceRoot()->itemChanged(items_to_update); getParentServiceRoot()->itemChanged(items_to_update);
}
return updated_messages; return updated_messages;
} }

View File

@ -397,6 +397,18 @@ bool ServiceRoot::markFeedsReadUnread(QList<Feed*> items, RootItem::ReadStatus r
} }
} }
QStringList ServiceRoot::textualFeedUrls(const QList<Feed*>& feeds) const {
QStringList stringy_urls;
stringy_urls.reserve(feeds.size());
foreach (const Feed* feed, feeds) {
stringy_urls.append(!feed->url().isEmpty() ? feed->url() : QL1S("no-url"));
}
return stringy_urls;
}
QStringList ServiceRoot::textualFeedIds(const QList<Feed*>& feeds) const { QStringList ServiceRoot::textualFeedIds(const QList<Feed*>& feeds) const {
QStringList stringy_ids; QStringList stringy_ids;
@ -439,19 +451,20 @@ void ServiceRoot::setAccountId(int account_id) {
bool ServiceRoot::loadMessagesForItem(RootItem* item, MessagesModel* model) { bool ServiceRoot::loadMessagesForItem(RootItem* item, MessagesModel* model) {
if (item->kind() == RootItemKind::Bin) { if (item->kind() == RootItemKind::Bin) {
model->setFilter(QString("Messages.is_deleted = 1 AND Messages.is_pdeleted = 0 AND Messages.account_id = %1").arg(QString::number( model->setFilter(QString("Messages.is_deleted = 1 AND Messages.is_pdeleted = 0 AND Messages.account_id = %1")
accountId()))); .arg(QString::number(accountId())));
} }
else { else {
QList<Feed*> children = item->getSubTreeFeeds(); QList<Feed*> children = item->getSubTreeFeeds();
QString filter_clause = textualFeedIds(children).join(QSL(", ")); QString filter_clause = textualFeedIds(children).join(QSL(", "));
QString urls = textualFeedUrls(children).join(QSL(", "));
model->setFilter( model->setFilter(
QString("Feeds.custom_id IN (%1) AND Messages.is_deleted = 0 AND Messages.is_pdeleted = 0 AND Messages.account_id = %2").arg( QString("Feeds.custom_id IN (%1) AND Messages.is_deleted = 0 AND Messages.is_pdeleted = 0 AND Messages.account_id = %2").arg(
filter_clause, filter_clause,
QString:: QString::
number(accountId()))); number(accountId())));
qDebug("Loading messages from feeds: %s.", qPrintable(filter_clause)); qDebug("Displaying messages from feeds IDs: %s and URLs: %s.", qPrintable(filter_clause), qPrintable(urls));
} }
return true; return true;

View File

@ -173,6 +173,7 @@ class ServiceRoot : public RootItem {
// from another machine and then performs sync-in on this machine. // from another machine and then performs sync-in on this machine.
void removeLeftOverMessages(); void removeLeftOverMessages();
QStringList textualFeedUrls(const QList<Feed*>& feeds) const;
QStringList textualFeedIds(const QList<Feed*>& feeds) const; QStringList textualFeedIds(const QList<Feed*>& feeds) const;
QStringList customIDsOfMessages(const QList<ImportanceChange>& changes); QStringList customIDsOfMessages(const QList<ImportanceChange>& changes);
QStringList customIDsOfMessages(const QList<Message>& messages); QStringList customIDsOfMessages(const QList<Message>& messages);

View File

@ -84,7 +84,7 @@ Message AtomParser::extractMessage(const QDomElement& msg_element, QDateTime cur
if (attribute == QSL("enclosure")) { if (attribute == QSL("enclosure")) {
new_message.m_enclosures.append(Enclosure(link.attribute(QSL("href")), link.attribute(QSL("type")))); new_message.m_enclosures.append(Enclosure(link.attribute(QSL("href")), link.attribute(QSL("type"))));
qDebug("Adding enclosure '%s' for the message.", qPrintable(new_message.m_enclosures.last().m_url)); qDebug("Found enclosure '%s' for the message.", qPrintable(new_message.m_enclosures.last().m_url));
} }
else if (attribute.isEmpty() || attribute == QSL("alternate")) { else if (attribute.isEmpty() || attribute == QSL("alternate")) {
last_link_alternate = link.attribute(QSL("href")); last_link_alternate = link.attribute(QSL("href"));

View File

@ -58,7 +58,7 @@ Message RssParser::extractMessage(const QDomElement& msg_element, QDateTime curr
if (!elem_enclosure.isEmpty()) { if (!elem_enclosure.isEmpty()) {
new_message.m_enclosures.append(Enclosure(elem_enclosure, elem_enclosure_type)); new_message.m_enclosures.append(Enclosure(elem_enclosure, elem_enclosure_type));
qDebug("Adding enclosure '%s' for the message.", qPrintable(elem_enclosure)); qDebug("Found enclosure '%s' for the message.", qPrintable(elem_enclosure));
} }
// Deal with link and author. // Deal with link and author.

View File

@ -418,7 +418,7 @@ QList<Message> StandardFeed::obtainNewMessages(bool* error_during_obtaining) {
*error_during_obtaining = true; *error_during_obtaining = true;
return QList<Message>(); return QList<Message>();
} }
else if (status() != NewMessages) { else {
*error_during_obtaining = false; *error_during_obtaining = false;
} }