diff --git a/resources/binaries b/resources/binaries index ae7084718..4a01edaec 160000 --- a/resources/binaries +++ b/resources/binaries @@ -1 +1 @@ -Subproject commit ae7084718c41afc01919779e58cd449e0eebd401 +Subproject commit 4a01edaec7d67d3b2ae81aeea2a3c876216fbab8 diff --git a/src/core/feeddownloader.cpp b/src/core/feeddownloader.cpp index 49f1b592e..57a5fea3e 100755 --- a/src/core/feeddownloader.cpp +++ b/src/core/feeddownloader.cpp @@ -34,21 +34,15 @@ bool FeedDownloader::isUpdateRunning() const { } void FeedDownloader::updateAvailableFeeds() { - QList caches; - foreach (const Feed* feed, m_feeds) { CacheForServiceRoot* cache = dynamic_cast(feed->getParentServiceRoot()); - if (cache != nullptr && !caches.contains(cache)) { - caches.append(cache); + if (cache != nullptr) { + qDebug("Saving cache for feed with DB ID %d and title '%s'.", feed->id(), qPrintable(feed->title())); + cache->saveAllCachedData(false); } } - // Now, we synchronously save cached data. - foreach (CacheForServiceRoot* cache, caches) { - cache->saveAllCachedData(false); - } - while (!m_feeds.isEmpty()) { connect(m_feeds.first(), &Feed::messagesObtained, this, &FeedDownloader::oneFeedUpdateFinished, (Qt::ConnectionType)(Qt::UniqueConnection | Qt::AutoConnection)); @@ -58,6 +52,8 @@ void FeedDownloader::updateAvailableFeeds() { m_feedsUpdating++; } 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. break; } @@ -103,9 +99,10 @@ void FeedDownloader::oneFeedUpdateFinished(const QList& messages, bool updateAvailableFeeds(); // Now make sure, that messages are actually stored to SQL in a locked state. - qDebug().nospace() << "Saving messages of feed " - << feed->customId() << " in thread: \'" + qDebug().nospace() << "Saving messages of feed ID " + << feed->customId() << " URL: " << feed->url() << " title: " << feed->title() << " in thread: \'" << QThread::currentThreadId() << "\'."; + int updated_messages = feed->updateMessages(messages, error_during_obtaining); qDebug("%d messages for feed %s stored in DB.", updated_messages, qPrintable(feed->customId())); diff --git a/src/main.cpp b/src/main.cpp index 5383d9e3b..79dd3caeb 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -67,6 +67,7 @@ int main(int argc, char* argv[]) { QDir::separator() + QL1S("rssguard.log")); } + qDebug("Starting %s.", qPrintable(QSL(APP_LONG_NAME))); qDebug("Instantiated Application class."); // Check if another instance is running. diff --git a/src/miscellaneous/databasequeries.cpp b/src/miscellaneous/databasequeries.cpp index 32aba4349..aa2025be5 100755 --- a/src/miscellaneous/databasequeries.cpp +++ b/src/miscellaneous/databasequeries.cpp @@ -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(":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()) { id_existing_message = query_select_with_url.value(0).toInt(); date_existing_message = query_select_with_url.value(1).value(); @@ -529,6 +532,9 @@ int DatabaseQueries::updateMessages(QSqlDatabase db, is_important_existing_message = query_select_with_url.value(3).toBool(); contents_existing_message = query_select_with_url.value(4).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()) { 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(":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()) { id_existing_message = query_select_with_id.value(0).toInt(); date_existing_message = query_select_with_id.value(1).value(); @@ -549,6 +557,9 @@ int DatabaseQueries::updateMessages(QSqlDatabase db, is_important_existing_message = query_select_with_id.value(3).toBool(); contents_existing_message = query_select_with_id.value(4).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()) { 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); *any_message_changed = true; - if (query_update.exec() && !message.m_isRead) { - updated_messages++; + 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++; + } } else if (query_update.lastError().isValid()) { qWarning("Failed to update message in DB: '%s'.", qPrintable(query_update.lastError().text())); } query_update.finish(); - qDebug("Updating message '%s' in DB.", qPrintable(message.m_title)); } } else { @@ -613,7 +627,7 @@ int DatabaseQueries::updateMessages(QSqlDatabase db, if (query_insert.exec() && query_insert.numRowsAffected() == 1) { 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()) { qWarning("Failed to insert message to DB: '%s' - message title is '%s'.", diff --git a/src/miscellaneous/feedreader.cpp b/src/miscellaneous/feedreader.cpp index b861b797a..d1628547e 100755 --- a/src/miscellaneous/feedreader.cpp +++ b/src/miscellaneous/feedreader.cpp @@ -69,6 +69,8 @@ void FeedReader::updateFeeds(const QList& feeds) { } if (m_feedDownloader == nullptr) { + qDebug("Creating FeedDownloader singleton."); + m_feedDownloader = new FeedDownloader(); m_feedDownloaderThread = new QThread(); diff --git a/src/services/abstract/feed.cpp b/src/services/abstract/feed.cpp index be318f336..b64cae10c 100755 --- a/src/services/abstract/feed.cpp +++ b/src/services/abstract/feed.cpp @@ -163,15 +163,16 @@ void Feed::updateCounts(bool including_total_count) { } void Feed::run() { - qDebug().nospace() << "Downloading new messages for feed " - << customId() << " in thread: \'" + qDebug().nospace() << "Downloading new messages for feed ID " + << customId() << " URL: " << url() << " title: " << title() << " in thread: \'" << QThread::currentThreadId() << "\'."; bool error_during_obtaining = false; QList 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() << "\'."; // Now, do some general operations on messages (tweak encoding etc.). @@ -229,6 +230,9 @@ int Feed::updateMessages(const QList& messages, bool error_during_obtai updated_messages = DatabaseQueries::updateMessages(database, messages, custom_id, account_id, url(), &anything_updated, &ok); } + else { + qWarning("There are no messages for update."); + } if (ok) { setStatus(updated_messages > 0 ? NewMessages : Normal); @@ -244,8 +248,12 @@ int Feed::updateMessages(const QList& messages, bool error_during_obtai qCritical("There is indication that there was error during messages obtaining."); } - items_to_update.append(this); - getParentServiceRoot()->itemChanged(items_to_update); + if (ok && !messages.isEmpty()) { + // Some messages were really added to DB, reload feed in model. + items_to_update.append(this); + getParentServiceRoot()->itemChanged(items_to_update); + } + return updated_messages; } diff --git a/src/services/abstract/serviceroot.cpp b/src/services/abstract/serviceroot.cpp index 90a08304a..3b2dfb1d9 100755 --- a/src/services/abstract/serviceroot.cpp +++ b/src/services/abstract/serviceroot.cpp @@ -397,6 +397,18 @@ bool ServiceRoot::markFeedsReadUnread(QList items, RootItem::ReadStatus r } } +QStringList ServiceRoot::textualFeedUrls(const QList& 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& feeds) const { QStringList stringy_ids; @@ -439,19 +451,20 @@ void ServiceRoot::setAccountId(int account_id) { bool ServiceRoot::loadMessagesForItem(RootItem* item, MessagesModel* model) { 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( - accountId()))); + model->setFilter(QString("Messages.is_deleted = 1 AND Messages.is_pdeleted = 0 AND Messages.account_id = %1") + .arg(QString::number(accountId()))); } else { QList children = item->getSubTreeFeeds(); QString filter_clause = textualFeedIds(children).join(QSL(", ")); + QString urls = textualFeedUrls(children).join(QSL(", ")); model->setFilter( QString("Feeds.custom_id IN (%1) AND Messages.is_deleted = 0 AND Messages.is_pdeleted = 0 AND Messages.account_id = %2").arg( filter_clause, QString:: 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; diff --git a/src/services/abstract/serviceroot.h b/src/services/abstract/serviceroot.h index 67ccd4bce..634a96a0e 100755 --- a/src/services/abstract/serviceroot.h +++ b/src/services/abstract/serviceroot.h @@ -173,6 +173,7 @@ class ServiceRoot : public RootItem { // from another machine and then performs sync-in on this machine. void removeLeftOverMessages(); + QStringList textualFeedUrls(const QList& feeds) const; QStringList textualFeedIds(const QList& feeds) const; QStringList customIDsOfMessages(const QList& changes); QStringList customIDsOfMessages(const QList& messages); diff --git a/src/services/standard/atomparser.cpp b/src/services/standard/atomparser.cpp index 2395cd62b..a1d4ac505 100755 --- a/src/services/standard/atomparser.cpp +++ b/src/services/standard/atomparser.cpp @@ -84,7 +84,7 @@ Message AtomParser::extractMessage(const QDomElement& msg_element, QDateTime cur if (attribute == QSL("enclosure")) { 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")) { last_link_alternate = link.attribute(QSL("href")); diff --git a/src/services/standard/rssparser.cpp b/src/services/standard/rssparser.cpp index c6189b243..6a22d3878 100755 --- a/src/services/standard/rssparser.cpp +++ b/src/services/standard/rssparser.cpp @@ -58,7 +58,7 @@ Message RssParser::extractMessage(const QDomElement& msg_element, QDateTime curr if (!elem_enclosure.isEmpty()) { 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. diff --git a/src/services/standard/standardfeed.cpp b/src/services/standard/standardfeed.cpp index ede63646e..c85d937e4 100755 --- a/src/services/standard/standardfeed.cpp +++ b/src/services/standard/standardfeed.cpp @@ -418,7 +418,7 @@ QList StandardFeed::obtainNewMessages(bool* error_during_obtaining) { *error_during_obtaining = true; return QList(); } - else if (status() != NewMessages) { + else { *error_during_obtaining = false; }