Skip to content

Commit

Permalink
imporve config comparison, to prevent uneeded datatype saves.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Jump committed Sep 26, 2019
1 parent 7ad5426 commit 6312dfd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
32 changes: 26 additions & 6 deletions uSync8.Core/Serialization/Serializers/DataTypeSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ protected override SyncAttempt<IDataType> DeserializeCore(XElement node)
if (item == null) throw new ArgumentException($"Cannot find underling datatype for {name}");

// basic
item.Name = name;
item.Key = key;
if (item.Name != name)
item.Name = name;

if (item.Key != key)
item.Key = key;

var editorAlias = info.Element("EditorAlias").ValueOrDefault(string.Empty);
if (editorAlias != item.EditorAlias)
Expand All @@ -63,7 +66,9 @@ protected override SyncAttempt<IDataType> DeserializeCore(XElement node)
// and can change based on minor things (so gives false out of sync results)

// item.SortOrder = info.Element("SortOrder").ValueOrDefault(0);
item.DatabaseType = info.Element("DatabaseType").ValueOrDefault(ValueStorageType.Nvarchar);
var dbType = info.Element("DatabaseType").ValueOrDefault(ValueStorageType.Nvarchar);
if (item.DatabaseType != dbType)
item.DatabaseType = dbType;

// config
DeserializeConfiguration(item, node);
Expand Down Expand Up @@ -96,20 +101,35 @@ private void DeserializeConfiguration(IDataType item, XElement node)

if (!string.IsNullOrWhiteSpace(config))
{

var serializer = this.configurationSerializers.GetSerializer(item.EditorAlias);
if (serializer == null)
{
item.Configuration = JsonConvert.DeserializeObject(config, item.Configuration.GetType());
var configObject = JsonConvert.DeserializeObject(config, item.Configuration.GetType());
if (!IsJsonEqual(item.Configuration, configObject))
item.Configuration = configObject;
}
else
{
logger.Debug<DataTypeSerializer>("Deserializing Config via {0}", serializer.Name);
item.Configuration = serializer.DeserializeConfig(config, item.Configuration.GetType());
var configObject = serializer.DeserializeConfig(config, item.Configuration.GetType());
if (!IsJsonEqual(item.Configuration, configObject))
item.Configuration = configObject;
}
}
}

/// <summary>
/// tells us if the json for an object is equal, helps when the config objects don't have their
/// own Equals functions
/// </summary>
private bool IsJsonEqual(object currentObject, object newObject)
{
var currentString = JsonConvert.SerializeObject(currentObject, Formatting.None);
var newString = JsonConvert.SerializeObject(newObject, Formatting.None);

return currentString == newString;
}


///////////////////////

Expand Down
2 changes: 1 addition & 1 deletion uSync8.Site/config/uSync8.config
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<ReportDebug>False</ReportDebug>
<HandlerSets default="default" Default="default">
<Handlers Name="default">
<Handler Alias="dataTypeHandler" Enabled="false" Actions="All" />
<Handler Alias="dataTypeHandler" Enabled="true" Actions="All" />
<Handler Alias="languageHandler" Enabled="true" Actions="All" />
<Handler Alias="macroHandler" Enabled="true" Actions="All" />
<Handler Alias="memberTypeHandler" Enabled="true" Actions="All" />
Expand Down

0 comments on commit 6312dfd

Please sign in to comment.