diff --git a/src/blackmisc/datacache.cpp b/src/blackmisc/datacache.cpp index ab523e301..3ff0319a7 100644 --- a/src/blackmisc/datacache.cpp +++ b/src/blackmisc/datacache.cpp @@ -257,6 +257,8 @@ namespace BlackMisc { CValueCachePacket newValues; auto msg = m_cache->loadFromFiles(persistentStore(), m_cache->m_revision.keysWithNewerTimestamps(), baseline.toVariantMap(), newValues, m_cache->m_revision.timestampsAsString()); + newValues.setTimestamps(m_cache->m_revision.newerTimestamps()); + msg.setCategories(this); CLogMessage::preformatted(msg); m_deferredChanges.insert(newValues); @@ -431,6 +433,14 @@ namespace BlackMisc return QSet::fromList(m_timestamps.keys()); } + const QMap &CDataCacheRevision::newerTimestamps() const + { + QMutexLocker lock(&m_mutex); + + Q_ASSERT(m_updateInProgress); + return m_timestamps; + } + bool CDataCacheRevision::isNewerValueAvailable(const QString &key, qint64 timestamp) { QMutexLocker lock(&m_mutex); diff --git a/src/blackmisc/datacache.h b/src/blackmisc/datacache.h index 392169828..4cbb1863a 100644 --- a/src/blackmisc/datacache.h +++ b/src/blackmisc/datacache.h @@ -117,6 +117,9 @@ namespace BlackMisc //! During update, returns keys which have on-disk timestamps newer than in-memory. Guaranteed not empty. QSet keysWithNewerTimestamps() const; + //! During update, returns timestamps which have on-disk timestamps newer than in-memory. Guaranteed not empty. + const QMap &newerTimestamps() const; + //! During update, returns true if the on-disk timestamp of this key is newer than in-memory. bool isNewerValueAvailable(const QString &key, qint64 timestamp); diff --git a/src/blackmisc/valuecache.cpp b/src/blackmisc/valuecache.cpp index bb5c505c6..d22b5b8bd 100644 --- a/src/blackmisc/valuecache.cpp +++ b/src/blackmisc/valuecache.cpp @@ -102,6 +102,15 @@ namespace BlackMisc return result.join(","); } + void CValueCachePacket::setTimestamps(const QMap ×) + { + for (auto it = times.cbegin(); it != times.cend(); ++it) + { + if (! contains(it.key())) { continue; } + (*this)[it.key()].second = it.value(); + } + } + CValueCachePacket CValueCachePacket::takeByKey(const QString &key) { auto copy = *this; diff --git a/src/blackmisc/valuecache.h b/src/blackmisc/valuecache.h index c62aed5f9..646d025b7 100644 --- a/src/blackmisc/valuecache.h +++ b/src/blackmisc/valuecache.h @@ -96,6 +96,9 @@ namespace BlackMisc //! Return map of timestamps converted to string. QString toTimestampMapString(const QStringList &keys) const; + //! Change the timestamps of values. + void setTimestamps(const QMap &); + //! Remove value matching the given key, and return it in a separate packet. CValueCachePacket takeByKey(const QString &key);