Fix cache refresh handling for unsaved records
- Preserve NEW_RECORD entries during cache refresh - Prevent accidental deletion of pending datastore changes - Clean up only stale persisted records
This commit is contained in:
@@ -230,9 +230,17 @@ void DataStore::refreshCache(util::Map<std::string, TrackedRecord<TObject>>& cac
|
|||||||
for (int index = 0; index < oldCache.getSize(); ++index)
|
for (int index = 0; index < oldCache.getSize(); ++index)
|
||||||
{
|
{
|
||||||
const std::string& id = oldCache.getKeyAt(index);
|
const std::string& id = oldCache.getKeyAt(index);
|
||||||
|
const TrackedRecord<TObject>& localTrackedRecord = oldCache.getValueAt(index);
|
||||||
if (cache.find(id) == -1)
|
if (cache.find(id) == -1)
|
||||||
{
|
{
|
||||||
delete oldCache.getValueAt(index).data;
|
if (localTrackedRecord.state == RecordState::NEW_RECORD)
|
||||||
|
{
|
||||||
|
cache.insert(id, localTrackedRecord);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
delete localTrackedRecord.data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user