mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 15:25:35 +08:00
Caches: method to save values given a list of keys.
This commit is contained in:
@@ -181,6 +181,18 @@ namespace BlackMisc
|
||||
return map;
|
||||
}
|
||||
|
||||
CVariantMap CValueCache::getAllValues(const QStringList &keys) const
|
||||
{
|
||||
QMutexLocker lock(&m_mutex);
|
||||
CVariantMap map;
|
||||
for (const auto &key : keys)
|
||||
{
|
||||
auto it = m_elements.constFind(key);
|
||||
if (it != m_elements.cend()) { map.insert(key, (*it)->m_value); }
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
CValueCachePacket CValueCache::getAllValuesWithTimestamps(const QString &keyPrefix) const
|
||||
{
|
||||
QMutexLocker lock(&m_mutex);
|
||||
@@ -299,6 +311,15 @@ namespace BlackMisc
|
||||
return status;
|
||||
}
|
||||
|
||||
CStatusMessage CValueCache::saveToFiles(const QString &dir, const QStringList &keys)
|
||||
{
|
||||
QMutexLocker lock(&m_mutex);
|
||||
auto values = getAllValues(keys);
|
||||
auto status = saveToFiles(dir, values);
|
||||
if (status.isSuccess()) { markAllAsSaved(keys); }
|
||||
return status;
|
||||
}
|
||||
|
||||
CStatusMessage CValueCache::saveToFiles(const QString &dir, const CVariantMap &values, const QString &keysMessage) const
|
||||
{
|
||||
QMap<QString, CVariantMap> namespaces;
|
||||
@@ -398,6 +419,15 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
void CValueCache::markAllAsSaved(const QStringList &keys)
|
||||
{
|
||||
QMutexLocker lock(&m_mutex);
|
||||
for (const auto &key : keys)
|
||||
{
|
||||
getElement(key).m_saved = true;
|
||||
}
|
||||
}
|
||||
|
||||
QString CValueCache::filenameForKey(const QString &key)
|
||||
{
|
||||
return key.section('/', 0, 0) + ".json";
|
||||
|
||||
Reference in New Issue
Block a user