mirror of
https://github.com/martinrotter/rssguard.git
synced 2025-02-03 10:47:47 +01:00
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:
parent
98c5ae234d
commit
a93c14ddc5
@ -1 +1 @@
|
||||
Subproject commit ae7084718c41afc01919779e58cd449e0eebd401
|
||||
Subproject commit 4a01edaec7d67d3b2ae81aeea2a3c876216fbab8
|
@ -34,21 +34,15 @@ bool FeedDownloader::isUpdateRunning() const {
|
||||
}
|
||||
|
||||
void FeedDownloader::updateAvailableFeeds() {
|
||||
QList<CacheForServiceRoot*> caches;
|
||||
|
||||
foreach (const Feed* feed, m_feeds) {
|
||||
CacheForServiceRoot* cache = dynamic_cast<CacheForServiceRoot*>(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<Message>& 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()));
|
||||
|
@ -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.
|
||||
|
@ -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<qint64>();
|
||||
@ -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<qint64>();
|
||||
@ -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'.",
|
||||
|
@ -69,6 +69,8 @@ void FeedReader::updateFeeds(const QList<Feed*>& feeds) {
|
||||
}
|
||||
|
||||
if (m_feedDownloader == nullptr) {
|
||||
qDebug("Creating FeedDownloader singleton.");
|
||||
|
||||
m_feedDownloader = new FeedDownloader();
|
||||
m_feedDownloaderThread = new QThread();
|
||||
|
||||
|
@ -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<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() << "\'.";
|
||||
|
||||
// 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);
|
||||
}
|
||||
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<Message>& 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;
|
||||
}
|
||||
|
||||
|
@ -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 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<Feed*> 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;
|
||||
|
@ -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<Feed*>& feeds) const;
|
||||
QStringList textualFeedIds(const QList<Feed*>& feeds) const;
|
||||
QStringList customIDsOfMessages(const QList<ImportanceChange>& changes);
|
||||
QStringList customIDsOfMessages(const QList<Message>& messages);
|
||||
|
@ -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"));
|
||||
|
@ -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.
|
||||
|
@ -418,7 +418,7 @@ QList<Message> StandardFeed::obtainNewMessages(bool* error_during_obtaining) {
|
||||
*error_during_obtaining = true;
|
||||
return QList<Message>();
|
||||
}
|
||||
else if (status() != NewMessages) {
|
||||
else {
|
||||
*error_during_obtaining = false;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user