refs #664 Use timestamps from .rev file instead of the filesystem timestamps of the json files.

This commit is contained in:
Mathew Sutcliffe
2016-05-26 18:03:21 +01:00
parent 4bc8326389
commit d0d100da5e
4 changed files with 25 additions and 0 deletions

View File

@@ -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<QString>::fromList(m_timestamps.keys());
}
const QMap<QString, qint64> &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);

View File

@@ -117,6 +117,9 @@ namespace BlackMisc
//! During update, returns keys which have on-disk timestamps newer than in-memory. Guaranteed not empty.
QSet<QString> keysWithNewerTimestamps() const;
//! During update, returns timestamps which have on-disk timestamps newer than in-memory. Guaranteed not empty.
const QMap<QString, qint64> &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);

View File

@@ -102,6 +102,15 @@ namespace BlackMisc
return result.join(",");
}
void CValueCachePacket::setTimestamps(const QMap<QString, qint64> &times)
{
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;

View File

@@ -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<QString, qint64> &);
//! Remove value matching the given key, and return it in a separate packet.
CValueCachePacket takeByKey(const QString &key);