diff --git a/Storage/Storage/Public/AVObject.cs b/Storage/Storage/Public/AVObject.cs index 3ded4cc..3898e28 100644 --- a/Storage/Storage/Public/AVObject.cs +++ b/Storage/Storage/Public/AVObject.cs @@ -492,10 +492,10 @@ string propertyName if (HasCircleReference(this, new HashSet())) { throw new AVException(AVException.ErrorCode.CircleReference, "Found a circle dependency when save"); } - Stack batches = BatchObjects(new List { this }); + Stack batches = BatchObjects(new List { this }, false); await SaveBatches(batches, cancellationToken); - // TODO query - + IObjectState result = await ObjectController.SaveAsync(state, operationDict, fetchWhenSave, query, cancellationToken); + HandleSave(result); } /// @@ -509,7 +509,7 @@ string propertyName throw new AVException(AVException.ErrorCode.CircleReference, "Found a circle dependency when save"); } } - Stack batches = BatchObjects(objects); + Stack batches = BatchObjects(objects, true); await SaveBatches(batches, cancellationToken); } @@ -754,39 +754,6 @@ string propertyName } } - /// - /// Helper version of CollectDirtyChildren so that callers don't have to add the internally - /// used parameters. - /// - private static void CollectDirtyChildren(object node, IList dirtyChildren) { - CollectDirtyChildren(node, - dirtyChildren, - new HashSet(new IdentityEqualityComparer()), - new HashSet(new IdentityEqualityComparer())); - } - - /// - /// Returns true if the given object can be serialized for saving as a value - /// that is pointed to by a AVObject. - /// - private static bool CanBeSerializedAsValue(object value) { - return DeepTraversal(value, yieldRoot: true) - .OfType() - .All(o => o.ObjectId != null); - } - - private bool CanBeSerialized { - get { - // This method is only used for batching sets of objects for saveAll - // and when saving children automatically. Since it's only used to - // determine whether or not save should be called on them, it only - // needs to examine their current values, so we use estimatedData. - lock (mutex) { - return CanBeSerializedAsValue(estimatedData); - } - } - } - /// /// Adds a task to the queue for all of the given objects. /// @@ -1089,8 +1056,7 @@ string propertyName /// A AVRelation for the key. public AVRelation GetRelation(string key) where T : AVObject { // All the sanity checking is done when add or remove is called. - AVRelation relation = null; - TryGetValue(key, out relation); + TryGetValue(key, out AVRelation relation); return relation ?? new AVRelation(this, key); } @@ -1422,10 +1388,11 @@ string propertyName return false; } - static Stack BatchObjects(IEnumerable avObjects) { + static Stack BatchObjects(IEnumerable avObjects, bool containsSelf) { Stack batches = new Stack(); - // 根节点作为第一批次,不适用依赖引用的判断规则 - batches.Push(new Batch(avObjects)); + if (containsSelf) { + batches.Push(new Batch(avObjects)); + } IEnumerable deps = from avObj in avObjects select avObj.estimatedData.Values; do {