From 283bb2e58b844449abd3453bda82af32cf6fc6c7 Mon Sep 17 00:00:00 2001 From: oneRain Date: Fri, 6 Dec 2019 17:02:10 +0800 Subject: [PATCH] =?UTF-8?q?*=20ObjectTest.cs:=20fix:=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=BC=95=E7=94=A8=E5=B7=B2=E5=AD=98=E5=9C=A8=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E5=A4=9A=E6=AC=A1=E7=9A=84=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * AVObject.cs: --- Storage/Storage.Test/ObjectTest.cs | 12 +++++++++++- Storage/Storage/Public/AVObject.cs | 16 ++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Storage/Storage.Test/ObjectTest.cs b/Storage/Storage.Test/ObjectTest.cs index 6154554..038da98 100644 --- a/Storage/Storage.Test/ObjectTest.cs +++ b/Storage/Storage.Test/ObjectTest.cs @@ -293,5 +293,15 @@ namespace LeanCloud.Test { }; await p.Save(); } + + [Test] + public async Task SaveWithQuery() { + AVObject p = new AVObject("P"); + AVObject c1 = AVObject.CreateWithoutData("C1", "5dea05578a84ab00680b7ae5"); + AVObject c2 = new AVObject("C2"); + p["c"] = c1; + c1["c"] = c2; + await p.Save(); + } } -} \ No newline at end of file +} diff --git a/Storage/Storage/Public/AVObject.cs b/Storage/Storage/Public/AVObject.cs index 72739d0..d7ae6f6 100644 --- a/Storage/Storage/Public/AVObject.cs +++ b/Storage/Storage/Public/AVObject.cs @@ -1567,15 +1567,10 @@ string propertyName static Stack BatchObjects(IEnumerable avObjects) { Stack batches = new Stack(); + batches.Push(new Batch(avObjects)); - IEnumerable deps = avObjects; - do { - // 只添加本层依赖的 LCObject - IEnumerable depAVObjs = deps.OfType(); - if (depAVObjs.Any()) { - batches.Push(new Batch(depAVObjs)); - } - + IEnumerable deps = from avObj in avObjects select avObj.estimatedData.Values; + do { HashSet childSets = new HashSet(); foreach (object dep in deps) { IEnumerable children = null; @@ -1585,6 +1580,7 @@ string propertyName children = (dep as IDictionary).Values; } else if (dep is AVObject && (dep as AVObject).ObjectId == null) { // 如果依赖是 AVObject 类型并且还没有保存过,则应该遍历其依赖 + // TODO 这里应该是从 Operation 中查找新增的对象 children = (dep as AVObject).estimatedData.Values; } if (children != null) { @@ -1593,6 +1589,10 @@ string propertyName } } } + IEnumerable depAVObjs = deps.OfType().Where(o => o.ObjectId == null); + if (depAVObjs.Any()) { + batches.Push(new Batch(depAVObjs)); + } deps = childSets; } while (deps != null && deps.Any());