Merge custom data only when necessary (#3475)

This commit is contained in:
louib
2019-09-16 14:01:13 -04:00
committed by Jonathan White
parent c99b656279
commit c19703c39f
3 changed files with 33 additions and 12 deletions

View File

@@ -622,11 +622,11 @@ Merger::ChangeList Merger::mergeMetadata(const MergeContext& context)
}
// Merge Custom Data if source is newer
const auto targetCustomDataModificationTime = sourceMetadata->customData()->getLastModified();
const auto sourceCustomDataModificationTime = targetMetadata->customData()->getLastModified();
const auto targetCustomDataModificationTime = targetMetadata->customData()->getLastModified();
const auto sourceCustomDataModificationTime = sourceMetadata->customData()->getLastModified();
if (!targetMetadata->customData()->contains(CustomData::LastModified)
|| (targetCustomDataModificationTime.isValid() && sourceCustomDataModificationTime.isValid()
&& targetCustomDataModificationTime > sourceCustomDataModificationTime)) {
&& targetCustomDataModificationTime < sourceCustomDataModificationTime)) {
const auto sourceCustomDataKeys = sourceMetadata->customData()->keys();
const auto targetCustomDataKeys = targetMetadata->customData()->keys();
@@ -641,9 +641,18 @@ Merger::ChangeList Merger::mergeMetadata(const MergeContext& context)
// Transfer new/existing keys
for (const auto& key : sourceCustomDataKeys) {
auto value = sourceMetadata->customData()->value(key);
targetMetadata->customData()->set(key, value);
changes << tr("Adding custom data %1 [%2]").arg(key, value);
// Don't merge this meta field, it is updated automatically.
if (key == CustomData::LastModified) {
continue;
}
auto sourceValue = sourceMetadata->customData()->value(key);
auto targetValue = targetMetadata->customData()->value(key);
// Merge only if the values are not the same.
if (sourceValue != targetValue) {
targetMetadata->customData()->set(key, sourceValue);
changes << tr("Adding custom data %1 [%2]").arg(key, sourceValue);
}
}
}