* ObjectTest.cs: fix: 修复引用已存在对象保存多次的 bug
* AVObject.cs:
parent
48bcd68eec
commit
283bb2e58b
|
@ -293,5 +293,15 @@ namespace LeanCloud.Test {
|
||||||
};
|
};
|
||||||
await p.Save();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1567,15 +1567,10 @@ string propertyName
|
||||||
|
|
||||||
static Stack<Batch> BatchObjects(IEnumerable<AVObject> avObjects) {
|
static Stack<Batch> BatchObjects(IEnumerable<AVObject> avObjects) {
|
||||||
Stack<Batch> batches = new Stack<Batch>();
|
Stack<Batch> batches = new Stack<Batch>();
|
||||||
|
batches.Push(new Batch(avObjects));
|
||||||
|
|
||||||
IEnumerable<object> deps = avObjects;
|
IEnumerable<object> deps = from avObj in avObjects select avObj.estimatedData.Values;
|
||||||
do {
|
do {
|
||||||
// 只添加本层依赖的 LCObject
|
|
||||||
IEnumerable<AVObject> depAVObjs = deps.OfType<AVObject>();
|
|
||||||
if (depAVObjs.Any()) {
|
|
||||||
batches.Push(new Batch(depAVObjs));
|
|
||||||
}
|
|
||||||
|
|
||||||
HashSet<object> childSets = new HashSet<object>();
|
HashSet<object> childSets = new HashSet<object>();
|
||||||
foreach (object dep in deps) {
|
foreach (object dep in deps) {
|
||||||
IEnumerable children = null;
|
IEnumerable children = null;
|
||||||
|
@ -1585,6 +1580,7 @@ string propertyName
|
||||||
children = (dep as IDictionary).Values;
|
children = (dep as IDictionary).Values;
|
||||||
} else if (dep is AVObject && (dep as AVObject).ObjectId == null) {
|
} else if (dep is AVObject && (dep as AVObject).ObjectId == null) {
|
||||||
// 如果依赖是 AVObject 类型并且还没有保存过,则应该遍历其依赖
|
// 如果依赖是 AVObject 类型并且还没有保存过,则应该遍历其依赖
|
||||||
|
// TODO 这里应该是从 Operation 中查找新增的对象
|
||||||
children = (dep as AVObject).estimatedData.Values;
|
children = (dep as AVObject).estimatedData.Values;
|
||||||
}
|
}
|
||||||
if (children != null) {
|
if (children != null) {
|
||||||
|
@ -1593,6 +1589,10 @@ string propertyName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
IEnumerable<AVObject> depAVObjs = deps.OfType<AVObject>().Where(o => o.ObjectId == null);
|
||||||
|
if (depAVObjs.Any()) {
|
||||||
|
batches.Push(new Batch(depAVObjs));
|
||||||
|
}
|
||||||
deps = childSets;
|
deps = childSets;
|
||||||
} while (deps != null && deps.Any());
|
} while (deps != null && deps.Any());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue