From ebeb1ccf6e9da1061d634313d3c1613be178238c Mon Sep 17 00:00:00 2001 From: oneRain Date: Mon, 9 Dec 2019 16:48:04 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E8=A1=A5=E5=85=85=20save=20=E5=8D=95?= =?UTF-8?q?=E4=B8=AA=E5=AF=B9=E8=B1=A1=E6=97=B6=E7=9A=84=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Storage/Storage/Public/AVObject.cs | 51 ++++++------------------------ 1 file changed, 9 insertions(+), 42 deletions(-) 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 {