make intelligent downloading in greader be able to download unread msgs only if user wants

This commit is contained in:
Martin Rotter 2021-08-03 10:27:33 +02:00
parent 2e9792ad59
commit a894dcd44f
7 changed files with 49 additions and 27 deletions

View File

@ -35,11 +35,7 @@ void BaseNetworkAccessManager::loadSettings() {
void BaseNetworkAccessManager::onSslErrors(QNetworkReply* reply, const QList<QSslError>& error) { void BaseNetworkAccessManager::onSslErrors(QNetworkReply* reply, const QList<QSslError>& error) {
qWarningNN << LOGSEC_NETWORK qWarningNN << LOGSEC_NETWORK
<< "Ignoring SSL errors for" << "Ignoring SSL errors for"
<< QUOTE_W_SPACE(reply->url().toString()) << QUOTE_W_SPACE_DOT(reply->url().toString());
<< ":"
<< QUOTE_W_SPACE(reply->errorString())
<< "- code"
<< QUOTE_W_SPACE_DOT(reply->error());
reply->ignoreSslErrors(error); reply->ignoreSslErrors(error);
} }

View File

@ -316,11 +316,11 @@ bool ServiceRoot::wantsBaggedIdsOfExistingMessages() const {
} }
void ServiceRoot::aboutToBeginFeedFetching(const QList<Feed*>& feeds, void ServiceRoot::aboutToBeginFeedFetching(const QList<Feed*>& feeds,
const QHash<QString, QHash<BagOfMessages, QStringList>>& stated_msgs, const QHash<QString, QHash<BagOfMessages, QStringList>>& stated_messages,
const QHash<QString, QStringList>& tagged_msgs) { const QHash<QString, QStringList>& tagged_messages) {
Q_UNUSED(feeds) Q_UNUSED(feeds)
Q_UNUSED(stated_msgs) Q_UNUSED(stated_messages)
Q_UNUSED(tagged_msgs) Q_UNUSED(tagged_messages)
} }
void ServiceRoot::itemChanged(const QList<RootItem*>& items) { void ServiceRoot::itemChanged(const QList<RootItem*>& items) {

View File

@ -66,8 +66,8 @@ class ServiceRoot : public RootItem {
virtual void setCustomDatabaseData(const QVariantHash& data); virtual void setCustomDatabaseData(const QVariantHash& data);
virtual bool wantsBaggedIdsOfExistingMessages() const; virtual bool wantsBaggedIdsOfExistingMessages() const;
virtual void aboutToBeginFeedFetching(const QList<Feed*>& feeds, virtual void aboutToBeginFeedFetching(const QList<Feed*>& feeds,
const QHash<QString, QHash<ServiceRoot::BagOfMessages, QStringList>>& stated_msgs, const QHash<QString, QHash<ServiceRoot::BagOfMessages, QStringList>>& stated_messages,
const QHash<QString, QStringList>& tagged_msgs); const QHash<QString, QStringList>& tagged_messages);
// Returns list of specific actions for "Add new item" main window menu. // Returns list of specific actions for "Add new item" main window menu.
// So typical list of returned actions could look like: // So typical list of returned actions could look like:

View File

@ -121,11 +121,17 @@ QVariantHash GreaderNetwork::userInfo(const QNetworkProxy& proxy) {
return QJsonDocument::fromJson(output).object().toVariantHash(); return QJsonDocument::fromJson(output).object().toVariantHash();
} }
void GreaderNetwork::clearPrefetchedMessages() {
m_prefetchedMessages.clear();
}
void GreaderNetwork::prepareFeedFetching(GreaderServiceRoot* root, void GreaderNetwork::prepareFeedFetching(GreaderServiceRoot* root,
const QList<Feed*>& feeds, const QList<Feed*>& feeds,
const QHash<QString, QHash<ServiceRoot::BagOfMessages, QStringList>>& stated_msgs, const QHash<QString, QHash<ServiceRoot::BagOfMessages, QStringList>>& stated_messages,
const QHash<QString, QStringList>& tagged_msgs, const QHash<QString, QStringList>& tagged_messages,
const QNetworkProxy& proxy) { const QNetworkProxy& proxy) {
Q_UNUSED(tagged_messages)
m_prefetchedMessages.clear(); m_prefetchedMessages.clear();
double perc_of_fetching = (feeds.size() * 1.0) / root->getSubTreeFeeds().size(); double perc_of_fetching = (feeds.size() * 1.0) / root->getSubTreeFeeds().size();
@ -144,7 +150,7 @@ void GreaderNetwork::prepareFeedFetching(GreaderServiceRoot* root,
QSet<QString> remote_starred_ids(remote_starred_ids_list.begin(), remote_starred_ids_list.end()); QSet<QString> remote_starred_ids(remote_starred_ids_list.begin(), remote_starred_ids_list.end());
QSet<QString> local_starred_ids; QSet<QString> local_starred_ids;
QList<QHash<ServiceRoot::BagOfMessages, QStringList>> all_states = stated_msgs.values(); QList<QHash<ServiceRoot::BagOfMessages, QStringList>> all_states = stated_messages.values();
for (auto& lst : all_states) { for (auto& lst : all_states) {
auto s = lst.value(ServiceRoot::BagOfMessages::Starred); auto s = lst.value(ServiceRoot::BagOfMessages::Starred);
@ -183,7 +189,15 @@ void GreaderNetwork::prepareFeedFetching(GreaderServiceRoot* root,
local_read_ids.unite(QSet<QString>(r.begin(), r.end())); local_read_ids.unite(QSet<QString>(r.begin(), r.end()));
} }
auto not_downloaded = remote_all_ids - local_read_ids - local_unread_ids; QSet<QString> 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_unread = local_unread_ids.intersect(remote_read_ids);
auto moved_read = local_read_ids.intersect(remote_unread_ids); auto moved_read = local_read_ids.intersect(remote_unread_ids);
@ -204,6 +218,8 @@ QList<Message> GreaderNetwork::getMessagesIntelligently(ServiceRoot* root,
const QHash<QString, QStringList>& tagged_messages, const QHash<QString, QStringList>& tagged_messages,
Feed::Status& error, Feed::Status& error,
const QNetworkProxy& proxy) { const QNetworkProxy& proxy) {
Q_UNUSED(tagged_messages)
QList<Message> msgs; QList<Message> msgs;
if (!m_performGlobalFetching) { if (!m_performGlobalFetching) {
@ -238,7 +254,15 @@ QList<Message> GreaderNetwork::getMessagesIntelligently(ServiceRoot* root,
local_read_ids_list.end()); local_read_ids_list.end());
// 3. // 3.
auto not_downloaded = remote_all_ids - local_read_ids - local_unread_ids; QSet<QString> 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_unread = local_unread_ids.intersect(remote_read_ids);
auto moved_read = local_read_ids.intersect(remote_unread_ids); auto moved_read = local_read_ids.intersect(remote_unread_ids);
auto to_download = not_downloaded + moved_read + moved_unread; auto to_download = not_downloaded + moved_read + moved_unread;

View File

@ -40,10 +40,11 @@ class GreaderNetwork : public QObject {
QVariantHash userInfo(const QNetworkProxy& proxy); QVariantHash userInfo(const QNetworkProxy& proxy);
void clearPrefetchedMessages();
void prepareFeedFetching(GreaderServiceRoot* root, void prepareFeedFetching(GreaderServiceRoot* root,
const QList<Feed*>& feeds, const QList<Feed*>& feeds,
const QHash<QString, QHash<ServiceRoot::BagOfMessages, QStringList>>& stated_msgs, const QHash<QString, QHash<ServiceRoot::BagOfMessages, QStringList>>& stated_messages,
const QHash<QString, QStringList>& tagged_msgs, const QHash<QString, QStringList>& tagged_messages,
const QNetworkProxy& proxy); const QNetworkProxy& proxy);
QList<Message> getMessagesIntelligently(ServiceRoot* root, QList<Message> getMessagesIntelligently(ServiceRoot* root,

View File

@ -58,14 +58,15 @@ void GreaderServiceRoot::setCustomDatabaseData(const QVariantHash& data) {
} }
void GreaderServiceRoot::aboutToBeginFeedFetching(const QList<Feed*>& feeds, void GreaderServiceRoot::aboutToBeginFeedFetching(const QList<Feed*>& feeds,
const QHash<QString, QHash<BagOfMessages, QStringList>>& stated_msgs, const QHash<QString, QHash<BagOfMessages, QStringList>>& stated_messages,
const QHash<QString, QStringList>& tagged_msgs) { const QHash<QString, QStringList>& tagged_messages) {
// Prefetch starred messages. // Prefetch starred messages.
m_network->prepareFeedFetching(this, if (true /* intelligent downloading */) {
feeds, m_network->prepareFeedFetching(this, feeds, stated_messages, tagged_messages, networkProxy());
stated_msgs, }
tagged_msgs, else {
networkProxy()); m_network->clearPrefetchedMessages();
}
} }
QList<Message> GreaderServiceRoot::obtainNewMessages(Feed* feed, QList<Message> GreaderServiceRoot::obtainNewMessages(Feed* feed,

View File

@ -32,8 +32,8 @@ class GreaderServiceRoot : public ServiceRoot, public CacheForServiceRoot {
virtual QVariantHash customDatabaseData() const; virtual QVariantHash customDatabaseData() const;
virtual void setCustomDatabaseData(const QVariantHash& data); virtual void setCustomDatabaseData(const QVariantHash& data);
virtual void aboutToBeginFeedFetching(const QList<Feed*>& feeds, virtual void aboutToBeginFeedFetching(const QList<Feed*>& feeds,
const QHash<QString, QHash<ServiceRoot::BagOfMessages, QStringList>>& stated_msgs, const QHash<QString, QHash<ServiceRoot::BagOfMessages, QStringList>>& stated_messages,
const QHash<QString, QStringList>& tagged_msgs); const QHash<QString, QStringList>& tagged_messages);
virtual QList<Message> obtainNewMessages(Feed* feed, virtual QList<Message> obtainNewMessages(Feed* feed,
const QHash<ServiceRoot::BagOfMessages, QStringList>& stated_messages, const QHash<ServiceRoot::BagOfMessages, QStringList>& stated_messages,
const QHash<QString, QStringList>& tagged_messages); const QHash<QString, QStringList>& tagged_messages);