From a894dcd44f2f29196971200868e1c9a899a948dc Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Tue, 3 Aug 2021 10:27:33 +0200 Subject: [PATCH] make intelligent downloading in greader be able to download unread msgs only if user wants --- .../network-web/basenetworkaccessmanager.cpp | 6 +--- .../services/abstract/serviceroot.cpp | 8 ++--- .../services/abstract/serviceroot.h | 4 +-- .../services/greader/greadernetwork.cpp | 34 ++++++++++++++++--- .../services/greader/greadernetwork.h | 5 +-- .../services/greader/greaderserviceroot.cpp | 15 ++++---- .../services/greader/greaderserviceroot.h | 4 +-- 7 files changed, 49 insertions(+), 27 deletions(-) diff --git a/src/librssguard/network-web/basenetworkaccessmanager.cpp b/src/librssguard/network-web/basenetworkaccessmanager.cpp index 03a9605a0..fb4bf03e3 100644 --- a/src/librssguard/network-web/basenetworkaccessmanager.cpp +++ b/src/librssguard/network-web/basenetworkaccessmanager.cpp @@ -35,11 +35,7 @@ void BaseNetworkAccessManager::loadSettings() { void BaseNetworkAccessManager::onSslErrors(QNetworkReply* reply, const QList& error) { qWarningNN << LOGSEC_NETWORK << "Ignoring SSL errors for" - << QUOTE_W_SPACE(reply->url().toString()) - << ":" - << QUOTE_W_SPACE(reply->errorString()) - << "- code" - << QUOTE_W_SPACE_DOT(reply->error()); + << QUOTE_W_SPACE_DOT(reply->url().toString()); reply->ignoreSslErrors(error); } diff --git a/src/librssguard/services/abstract/serviceroot.cpp b/src/librssguard/services/abstract/serviceroot.cpp index d03112f22..7f5d8fcda 100644 --- a/src/librssguard/services/abstract/serviceroot.cpp +++ b/src/librssguard/services/abstract/serviceroot.cpp @@ -316,11 +316,11 @@ bool ServiceRoot::wantsBaggedIdsOfExistingMessages() const { } void ServiceRoot::aboutToBeginFeedFetching(const QList& feeds, - const QHash>& stated_msgs, - const QHash& tagged_msgs) { + const QHash>& stated_messages, + const QHash& tagged_messages) { Q_UNUSED(feeds) - Q_UNUSED(stated_msgs) - Q_UNUSED(tagged_msgs) + Q_UNUSED(stated_messages) + Q_UNUSED(tagged_messages) } void ServiceRoot::itemChanged(const QList& items) { diff --git a/src/librssguard/services/abstract/serviceroot.h b/src/librssguard/services/abstract/serviceroot.h index 224042acd..03b84b89f 100644 --- a/src/librssguard/services/abstract/serviceroot.h +++ b/src/librssguard/services/abstract/serviceroot.h @@ -66,8 +66,8 @@ class ServiceRoot : public RootItem { virtual void setCustomDatabaseData(const QVariantHash& data); virtual bool wantsBaggedIdsOfExistingMessages() const; virtual void aboutToBeginFeedFetching(const QList& feeds, - const QHash>& stated_msgs, - const QHash& tagged_msgs); + const QHash>& stated_messages, + const QHash& tagged_messages); // Returns list of specific actions for "Add new item" main window menu. // So typical list of returned actions could look like: diff --git a/src/librssguard/services/greader/greadernetwork.cpp b/src/librssguard/services/greader/greadernetwork.cpp index 3488961d0..e90e5a8ce 100755 --- a/src/librssguard/services/greader/greadernetwork.cpp +++ b/src/librssguard/services/greader/greadernetwork.cpp @@ -121,11 +121,17 @@ QVariantHash GreaderNetwork::userInfo(const QNetworkProxy& proxy) { return QJsonDocument::fromJson(output).object().toVariantHash(); } +void GreaderNetwork::clearPrefetchedMessages() { + m_prefetchedMessages.clear(); +} + void GreaderNetwork::prepareFeedFetching(GreaderServiceRoot* root, const QList& feeds, - const QHash>& stated_msgs, - const QHash& tagged_msgs, + const QHash>& stated_messages, + const QHash& tagged_messages, const QNetworkProxy& proxy) { + Q_UNUSED(tagged_messages) + m_prefetchedMessages.clear(); double perc_of_fetching = (feeds.size() * 1.0) / root->getSubTreeFeeds().size(); @@ -144,7 +150,7 @@ void GreaderNetwork::prepareFeedFetching(GreaderServiceRoot* root, QSet remote_starred_ids(remote_starred_ids_list.begin(), remote_starred_ids_list.end()); QSet local_starred_ids; - QList> all_states = stated_msgs.values(); + QList> all_states = stated_messages.values(); for (auto& lst : all_states) { auto s = lst.value(ServiceRoot::BagOfMessages::Starred); @@ -183,7 +189,15 @@ void GreaderNetwork::prepareFeedFetching(GreaderServiceRoot* root, local_read_ids.unite(QSet(r.begin(), r.end())); } - auto not_downloaded = remote_all_ids - local_read_ids - local_unread_ids; + QSet not_downloaded; + + if (!m_downloadOnlyUnreadMessages) { + not_downloaded = remote_all_ids - local_read_ids - local_unread_ids; + } + else { + not_downloaded = remote_unread_ids - local_read_ids - local_unread_ids; + } + auto moved_unread = local_unread_ids.intersect(remote_read_ids); auto moved_read = local_read_ids.intersect(remote_unread_ids); @@ -204,6 +218,8 @@ QList GreaderNetwork::getMessagesIntelligently(ServiceRoot* root, const QHash& tagged_messages, Feed::Status& error, const QNetworkProxy& proxy) { + Q_UNUSED(tagged_messages) + QList msgs; if (!m_performGlobalFetching) { @@ -238,7 +254,15 @@ QList GreaderNetwork::getMessagesIntelligently(ServiceRoot* root, local_read_ids_list.end()); // 3. - auto not_downloaded = remote_all_ids - local_read_ids - local_unread_ids; + QSet not_downloaded; + + if (!m_downloadOnlyUnreadMessages) { + not_downloaded = remote_all_ids - local_read_ids - local_unread_ids; + } + else { + not_downloaded = remote_unread_ids - local_read_ids - local_unread_ids; + } + auto moved_unread = local_unread_ids.intersect(remote_read_ids); auto moved_read = local_read_ids.intersect(remote_unread_ids); auto to_download = not_downloaded + moved_read + moved_unread; diff --git a/src/librssguard/services/greader/greadernetwork.h b/src/librssguard/services/greader/greadernetwork.h index d25132dfa..0d957ef17 100755 --- a/src/librssguard/services/greader/greadernetwork.h +++ b/src/librssguard/services/greader/greadernetwork.h @@ -40,10 +40,11 @@ class GreaderNetwork : public QObject { QVariantHash userInfo(const QNetworkProxy& proxy); + void clearPrefetchedMessages(); void prepareFeedFetching(GreaderServiceRoot* root, const QList& feeds, - const QHash>& stated_msgs, - const QHash& tagged_msgs, + const QHash>& stated_messages, + const QHash& tagged_messages, const QNetworkProxy& proxy); QList getMessagesIntelligently(ServiceRoot* root, diff --git a/src/librssguard/services/greader/greaderserviceroot.cpp b/src/librssguard/services/greader/greaderserviceroot.cpp index 3a6d460d0..7b82ef394 100755 --- a/src/librssguard/services/greader/greaderserviceroot.cpp +++ b/src/librssguard/services/greader/greaderserviceroot.cpp @@ -58,14 +58,15 @@ void GreaderServiceRoot::setCustomDatabaseData(const QVariantHash& data) { } void GreaderServiceRoot::aboutToBeginFeedFetching(const QList& feeds, - const QHash>& stated_msgs, - const QHash& tagged_msgs) { + const QHash>& stated_messages, + const QHash& tagged_messages) { // Prefetch starred messages. - m_network->prepareFeedFetching(this, - feeds, - stated_msgs, - tagged_msgs, - networkProxy()); + if (true /* intelligent downloading */) { + m_network->prepareFeedFetching(this, feeds, stated_messages, tagged_messages, networkProxy()); + } + else { + m_network->clearPrefetchedMessages(); + } } QList GreaderServiceRoot::obtainNewMessages(Feed* feed, diff --git a/src/librssguard/services/greader/greaderserviceroot.h b/src/librssguard/services/greader/greaderserviceroot.h index 2048158e0..f5609f6ab 100755 --- a/src/librssguard/services/greader/greaderserviceroot.h +++ b/src/librssguard/services/greader/greaderserviceroot.h @@ -32,8 +32,8 @@ class GreaderServiceRoot : public ServiceRoot, public CacheForServiceRoot { virtual QVariantHash customDatabaseData() const; virtual void setCustomDatabaseData(const QVariantHash& data); virtual void aboutToBeginFeedFetching(const QList& feeds, - const QHash>& stated_msgs, - const QHash& tagged_msgs); + const QHash>& stated_messages, + const QHash& tagged_messages); virtual QList obtainNewMessages(Feed* feed, const QHash& stated_messages, const QHash& tagged_messages);