Save account cache before account is edited.

This commit is contained in:
Martin Rotter 2021-01-11 11:23:09 +01:00
parent 25329b61fa
commit c1fe781b50
13 changed files with 37 additions and 25 deletions

@ -44,7 +44,7 @@ void FeedDownloader::updateAvailableFeeds() {
qDebugNN << LOGSEC_FEEDDOWNLOADER qDebugNN << LOGSEC_FEEDDOWNLOADER
<< "Saving cache for feed with DB ID '" << feed->id() << "Saving cache for feed with DB ID '" << feed->id()
<< "' and title '" << feed->title() << "'."; << "' and title '" << feed->title() << "'.";
cache->saveAllCachedData(); cache->saveAllCachedData(false);
} }
if (m_stopCacheSynchronization) { if (m_stopCacheSynchronization) {
@ -66,7 +66,7 @@ void FeedDownloader::synchronizeAccountCaches(const QList<CacheForServiceRoot*>&
for (CacheForServiceRoot* cache : caches) { for (CacheForServiceRoot* cache : caches) {
qDebugNN << LOGSEC_FEEDDOWNLOADER qDebugNN << LOGSEC_FEEDDOWNLOADER
<< "Synchronizing cache back to server on thread" << QUOTE_W_SPACE_DOT(QThread::currentThreadId()); << "Synchronizing cache back to server on thread" << QUOTE_W_SPACE_DOT(QThread::currentThreadId());
cache->saveAllCachedData(); cache->saveAllCachedData(false);
if (m_stopCacheSynchronization) { if (m_stopCacheSynchronization) {
qWarningNN << LOGSEC_FEEDDOWNLOADER << "Aborting cache synchronization."; qWarningNN << LOGSEC_FEEDDOWNLOADER << "Aborting cache synchronization.";

@ -22,7 +22,7 @@ class CacheForServiceRoot {
public: public:
explicit CacheForServiceRoot(); explicit CacheForServiceRoot();
virtual void saveAllCachedData() = 0; virtual void saveAllCachedData(bool ignore_errors) = 0;
void addLabelsAssignmentsToCache(const QStringList& ids_of_messages, const QString& lbl_custom_id, bool assign); void addLabelsAssignmentsToCache(const QStringList& ids_of_messages, const QString& lbl_custom_id, bool assign);
void addLabelsAssignmentsToCache(const QList<Message>& ids_of_messages, Label* lbl, bool assign); void addLabelsAssignmentsToCache(const QList<Message>& ids_of_messages, Label* lbl, bool assign);

@ -16,7 +16,17 @@ FormAccountDetails::FormAccountDetails(const QIcon& icon, QWidget* parent) : QDi
createConnections(); createConnections();
} }
void FormAccountDetails::apply() {} void FormAccountDetails::apply() {
if (m_account != nullptr) {
// Perform last-time operations before account is changed.
auto* cached_account = dynamic_cast<CacheForServiceRoot*>(m_account);
if (cached_account != nullptr) {
qWarningNN << LOGSEC_CORE << "Last-time account cache saving before account gets changed.";
cached_account->saveAllCachedData(true);
}
}
}
void FormAccountDetails::insertCustomTab(QWidget* custom_tab, const QString& title, int index) { void FormAccountDetails::insertCustomTab(QWidget* custom_tab, const QString& title, int index) {
m_ui.m_tabWidget->insertTab(index, custom_tab, title); m_ui.m_tabWidget->insertTab(index, custom_tab, title);

@ -94,7 +94,7 @@ QList<QAction*> ServiceRoot::serviceMenu() {
auto* act_sync_cache = new QAction(qApp->icons()->fromTheme(QSL("view-refresh")), tr("Synchronize message cache"), this); auto* act_sync_cache = new QAction(qApp->icons()->fromTheme(QSL("view-refresh")), tr("Synchronize message cache"), this);
connect(act_sync_cache, &QAction::triggered, this, [cache]() { connect(act_sync_cache, &QAction::triggered, this, [cache]() {
cache->saveAllCachedData(); cache->saveAllCachedData(false);
}); });
m_serviceMenu.append(act_sync_cache); m_serviceMenu.append(act_sync_cache);

@ -205,7 +205,7 @@ QString GmailServiceRoot::additionalTooltip() const {
network()->oauth()->tokensExpireIn().toString() : QSL("-")); network()->oauth()->tokensExpireIn().toString() : QSL("-"));
} }
void GmailServiceRoot::saveAllCachedData() { void GmailServiceRoot::saveAllCachedData(bool ignore_errors) {
auto msg_cache = takeMessageCache(); auto msg_cache = takeMessageCache();
QMapIterator<RootItem::ReadStatus, QStringList> i(msg_cache.m_cachedStatesRead); QMapIterator<RootItem::ReadStatus, QStringList> i(msg_cache.m_cachedStatesRead);
@ -216,7 +216,7 @@ void GmailServiceRoot::saveAllCachedData() {
QStringList ids = i.value(); QStringList ids = i.value();
if (!ids.isEmpty()) { if (!ids.isEmpty()) {
if (network()->markMessagesRead(key, ids) != QNetworkReply::NetworkError::NoError) { if (network()->markMessagesRead(key, ids) != QNetworkReply::NetworkError::NoError && !ignore_errors) {
addMessageStatesToCache(ids, key); addMessageStatesToCache(ids, key);
} }
} }
@ -237,7 +237,7 @@ void GmailServiceRoot::saveAllCachedData() {
custom_ids.append(msg.m_customId); custom_ids.append(msg.m_customId);
} }
if (network()->markMessagesStarred(key, custom_ids) != QNetworkReply::NetworkError::NoError) { if (network()->markMessagesStarred(key, custom_ids) != QNetworkReply::NetworkError::NoError && !ignore_errors) {
addMessageStatesToCache(messages, key); addMessageStatesToCache(messages, key);
} }
} }

@ -33,7 +33,7 @@ class GmailServiceRoot : public ServiceRoot, public CacheForServiceRoot {
virtual void start(bool freshly_activated); virtual void start(bool freshly_activated);
virtual QString code() const; virtual QString code() const;
virtual QString additionalTooltip() const; virtual QString additionalTooltip() const;
virtual void saveAllCachedData(); virtual void saveAllCachedData(bool ignore_errors);
void updateTitle(); void updateTitle();

@ -148,7 +148,7 @@ RootItem* InoreaderServiceRoot::obtainNewTreeForSyncIn() const {
} }
} }
void InoreaderServiceRoot::saveAllCachedData() { void InoreaderServiceRoot::saveAllCachedData(bool ignore_errors) {
auto msg_cache = takeMessageCache(); auto msg_cache = takeMessageCache();
QMapIterator<RootItem::ReadStatus, QStringList> i(msg_cache.m_cachedStatesRead); QMapIterator<RootItem::ReadStatus, QStringList> i(msg_cache.m_cachedStatesRead);
@ -159,7 +159,7 @@ void InoreaderServiceRoot::saveAllCachedData() {
QStringList ids = i.value(); QStringList ids = i.value();
if (!ids.isEmpty()) { if (!ids.isEmpty()) {
if (network()->markMessagesRead(key, ids) != QNetworkReply::NetworkError::NoError) { if (network()->markMessagesRead(key, ids) != QNetworkReply::NetworkError::NoError && !ignore_errors) {
addMessageStatesToCache(ids, key); addMessageStatesToCache(ids, key);
} }
} }
@ -180,7 +180,7 @@ void InoreaderServiceRoot::saveAllCachedData() {
custom_ids.append(msg.m_customId); custom_ids.append(msg.m_customId);
} }
if (network()->markMessagesStarred(key, custom_ids) != QNetworkReply::NetworkError::NoError) { if (network()->markMessagesStarred(key, custom_ids) != QNetworkReply::NetworkError::NoError && !ignore_errors) {
addMessageStatesToCache(messages, key); addMessageStatesToCache(messages, key);
} }
} }
@ -195,7 +195,7 @@ void InoreaderServiceRoot::saveAllCachedData() {
QStringList messages = k.value(); QStringList messages = k.value();
if (!messages.isEmpty()) { if (!messages.isEmpty()) {
if (network()->editLabels(label_custom_id, true, messages) != QNetworkReply::NetworkError::NoError) { if (network()->editLabels(label_custom_id, true, messages) != QNetworkReply::NetworkError::NoError && !ignore_errors) {
addLabelsAssignmentsToCache(messages, label_custom_id, true); addLabelsAssignmentsToCache(messages, label_custom_id, true);
} }
} }
@ -210,7 +210,7 @@ void InoreaderServiceRoot::saveAllCachedData() {
QStringList messages = l.value(); QStringList messages = l.value();
if (!messages.isEmpty()) { if (!messages.isEmpty()) {
if (network()->editLabels(label_custom_id, false, messages) != QNetworkReply::NetworkError::NoError) { if (network()->editLabels(label_custom_id, false, messages) != QNetworkReply::NetworkError::NoError && !ignore_errors) {
addLabelsAssignmentsToCache(messages, label_custom_id, false); addLabelsAssignmentsToCache(messages, label_custom_id, false);
} }
} }

@ -31,7 +31,7 @@ class InoreaderServiceRoot : public ServiceRoot, public CacheForServiceRoot {
virtual void start(bool freshly_activated); virtual void start(bool freshly_activated);
virtual QString code() const; virtual QString code() const;
virtual QString additionalTooltip() const; virtual QString additionalTooltip() const;
virtual void saveAllCachedData(); virtual void saveAllCachedData(bool ignore_errors);
void updateTitle(); void updateTitle();

@ -80,7 +80,7 @@ OwnCloudNetworkFactory* OwnCloudServiceRoot::network() const {
return m_network; return m_network;
} }
void OwnCloudServiceRoot::saveAllCachedData() { void OwnCloudServiceRoot::saveAllCachedData(bool ignore_errors) {
auto msg_cache = takeMessageCache(); auto msg_cache = takeMessageCache();
QMapIterator<RootItem::ReadStatus, QStringList> i(msg_cache.m_cachedStatesRead); QMapIterator<RootItem::ReadStatus, QStringList> i(msg_cache.m_cachedStatesRead);
@ -93,7 +93,7 @@ void OwnCloudServiceRoot::saveAllCachedData() {
if (!ids.isEmpty()) { if (!ids.isEmpty()) {
auto res = network()->markMessagesRead(key, ids); auto res = network()->markMessagesRead(key, ids);
if (res.first != QNetworkReply::NetworkError::NoError) { if (!ignore_errors && res.first != QNetworkReply::NetworkError::NoError) {
addMessageStatesToCache(ids, key); addMessageStatesToCache(ids, key);
} }
} }
@ -117,7 +117,7 @@ void OwnCloudServiceRoot::saveAllCachedData() {
auto res = network()->markMessagesStarred(key, feed_ids, guid_hashes); auto res = network()->markMessagesStarred(key, feed_ids, guid_hashes);
if (res.first != QNetworkReply::NetworkError::NoError) { if (!ignore_errors && res.first != QNetworkReply::NetworkError::NoError) {
addMessageStatesToCache(messages, key); addMessageStatesToCache(messages, key);
} }
} }

@ -27,7 +27,7 @@ class OwnCloudServiceRoot : public ServiceRoot, public CacheForServiceRoot {
virtual bool supportsCategoryAdding() const; virtual bool supportsCategoryAdding() const;
virtual void start(bool freshly_activated); virtual void start(bool freshly_activated);
virtual QString code() const; virtual QString code() const;
virtual void saveAllCachedData(); virtual void saveAllCachedData(bool ignore_errors);
OwnCloudNetworkFactory* network() const; OwnCloudNetworkFactory* network() const;

@ -28,6 +28,8 @@ TtRssServiceRoot* FormEditTtRssAccount::addEditAccount(TtRssServiceRoot* account
} }
void FormEditTtRssAccount::apply() { void FormEditTtRssAccount::apply() {
FormAccountDetails::apply();
bool editing_account = true; bool editing_account = true;
if (m_account == nullptr) { if (m_account == nullptr) {

@ -117,7 +117,7 @@ bool TtRssServiceRoot::canBeDeleted() const {
return true; return true;
} }
void TtRssServiceRoot::saveAllCachedData() { void TtRssServiceRoot::saveAllCachedData(bool ignore_errors) {
auto msg_cache = takeMessageCache(); auto msg_cache = takeMessageCache();
QMapIterator<RootItem::ReadStatus, QStringList> i(msg_cache.m_cachedStatesRead); QMapIterator<RootItem::ReadStatus, QStringList> i(msg_cache.m_cachedStatesRead);
@ -134,7 +134,7 @@ void TtRssServiceRoot::saveAllCachedData() {
? UpdateArticle::Mode::SetToTrue ? UpdateArticle::Mode::SetToTrue
: UpdateArticle::Mode::SetToFalse); : UpdateArticle::Mode::SetToFalse);
if (network()->lastError() != QNetworkReply::NetworkError::NoError || res.hasError()) { if (!ignore_errors && (network()->lastError() != QNetworkReply::NetworkError::NoError || res.hasError())) {
addMessageStatesToCache(ids, key); addMessageStatesToCache(ids, key);
} }
} }
@ -156,7 +156,7 @@ void TtRssServiceRoot::saveAllCachedData() {
? UpdateArticle::Mode::SetToTrue ? UpdateArticle::Mode::SetToTrue
: UpdateArticle::Mode::SetToFalse); : UpdateArticle::Mode::SetToFalse);
if (network()->lastError() != QNetworkReply::NetworkError::NoError || res.hasError()) { if (!ignore_errors && (network()->lastError() != QNetworkReply::NetworkError::NoError || res.hasError())) {
addMessageStatesToCache(messages, key); addMessageStatesToCache(messages, key);
} }
} }
@ -173,7 +173,7 @@ void TtRssServiceRoot::saveAllCachedData() {
if (!messages.isEmpty()) { if (!messages.isEmpty()) {
auto res = network()->setArticleLabel(messages, label_custom_id, true); auto res = network()->setArticleLabel(messages, label_custom_id, true);
if (network()->lastError() != QNetworkReply::NetworkError::NoError || res.hasError()) { if (!ignore_errors && (network()->lastError() != QNetworkReply::NetworkError::NoError || res.hasError())) {
addLabelsAssignmentsToCache(messages, label_custom_id, true); addLabelsAssignmentsToCache(messages, label_custom_id, true);
} }
} }
@ -190,7 +190,7 @@ void TtRssServiceRoot::saveAllCachedData() {
if (!messages.isEmpty()) { if (!messages.isEmpty()) {
auto res = network()->setArticleLabel(messages, label_custom_id, false); auto res = network()->setArticleLabel(messages, label_custom_id, false);
if (network()->lastError() != QNetworkReply::NetworkError::NoError || res.hasError()) { if (!ignore_errors && (network()->lastError() != QNetworkReply::NetworkError::NoError || res.hasError())) {
addLabelsAssignmentsToCache(messages, label_custom_id, false); addLabelsAssignmentsToCache(messages, label_custom_id, false);
} }
} }

@ -32,7 +32,7 @@ class TtRssServiceRoot : public ServiceRoot, public CacheForServiceRoot {
virtual bool supportsCategoryAdding() const; virtual bool supportsCategoryAdding() const;
virtual void addNewFeed(RootItem* selected_item, const QString& url = QString()); virtual void addNewFeed(RootItem* selected_item, const QString& url = QString());
virtual QString additionalTooltip() const; virtual QString additionalTooltip() const;
virtual void saveAllCachedData(); virtual void saveAllCachedData(bool ignore_errors);
// Access to network. // Access to network.
TtRssNetworkFactory* network() const; TtRssNetworkFactory* network() const;