Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update on null collection #302

Merged
merged 5 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/Redis.OM/Modeling/RedisCollectionStateManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
Expand Down Expand Up @@ -107,7 +107,7 @@ internal bool TryDetectDifferencesSingle(string key, object value, out IList<IOb
var current = JsonConvert.DeserializeObject<JObject>(dataJson, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
var snapshot = (JToken)Snapshot[key];
var diff = FindDiff(current!, snapshot);
differences = BuildJsonDifference(diff, "$");
differences = BuildJsonDifference(diff, "$", snapshot);
}
else
{
Expand Down Expand Up @@ -142,7 +142,7 @@ internal IDictionary<string, IList<IObjectDiff>> DetectDifferences()
var current = JsonConvert.DeserializeObject<JObject>(dataJson, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
var snapshot = (JToken)Snapshot[key];
var diff = FindDiff(current!, snapshot);
var diffArgs = BuildJsonDifference(diff, "$");
var diffArgs = BuildJsonDifference(diff, "$", snapshot);
res.Add(key, diffArgs);
}
else
Expand Down Expand Up @@ -178,7 +178,7 @@ internal IDictionary<string, IList<IObjectDiff>> DetectDifferences()
return res;
}

private static IList<IObjectDiff> BuildJsonDifference(JObject diff, string currentPath)
private static IList<IObjectDiff> BuildJsonDifference(JObject diff, string currentPath, JToken snapshot)
{
var ret = new List<IObjectDiff>();
if (diff.ContainsKey("+") && diff.ContainsKey("-"))
Expand All @@ -200,7 +200,7 @@ private static IList<IObjectDiff> BuildJsonDifference(JObject diff, string curre

if (diff.ContainsKey("+"))
{
if (diff["+"] is JArray arr)
if (diff["+"] is JArray arr && snapshot.SelectToken(diff.Path) is not null)
{
ret.AddRange(arr.Select(item => new JsonDiff("ARRAPPEND", currentPath, item)));
}
Expand Down Expand Up @@ -229,7 +229,7 @@ private static IList<IObjectDiff> BuildJsonDifference(JObject diff, string curre
foreach (var item in diff)
{
var val = item.Value as JObject;
ret.AddRange(BuildJsonDifference(val!, $"{currentPath}.{item.Key}"));
ret.AddRange(BuildJsonDifference(val!, $"{currentPath}.{item.Key}", snapshot));
}

return ret;
Expand Down
2 changes: 1 addition & 1 deletion src/Redis.OM/RedisObjectHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ internal static string SetId(this object obj)
}
else
{
idProperty.SetValue(obj, id);
idProperty.SetValue(obj, Convert.ChangeType(id, idProperty.PropertyType));
}
}
}
Expand Down
Loading