chore: 补充 save 单个对象时的条件设置

oneRain 2019-12-09 16:48:04 +08:00
parent 0bd113c4d6
commit ebeb1ccf6e
1 changed files with 9 additions and 42 deletions

View File

@ -492,10 +492,10 @@ string propertyName
if (HasCircleReference(this, new HashSet<AVObject>())) { if (HasCircleReference(this, new HashSet<AVObject>())) {
throw new AVException(AVException.ErrorCode.CircleReference, "Found a circle dependency when save"); throw new AVException(AVException.ErrorCode.CircleReference, "Found a circle dependency when save");
} }
Stack<Batch> batches = BatchObjects(new List<AVObject> { this }); Stack<Batch> batches = BatchObjects(new List<AVObject> { this }, false);
await SaveBatches(batches, cancellationToken); await SaveBatches(batches, cancellationToken);
// TODO query IObjectState result = await ObjectController.SaveAsync(state, operationDict, fetchWhenSave, query, cancellationToken);
HandleSave(result);
} }
/// <summary> /// <summary>
@ -509,7 +509,7 @@ string propertyName
throw new AVException(AVException.ErrorCode.CircleReference, "Found a circle dependency when save"); throw new AVException(AVException.ErrorCode.CircleReference, "Found a circle dependency when save");
} }
} }
Stack<Batch> batches = BatchObjects(objects); Stack<Batch> batches = BatchObjects(objects, true);
await SaveBatches(batches, cancellationToken); await SaveBatches(batches, cancellationToken);
} }
@ -754,39 +754,6 @@ string propertyName
} }
} }
/// <summary>
/// Helper version of CollectDirtyChildren so that callers don't have to add the internally
/// used parameters.
/// </summary>
private static void CollectDirtyChildren(object node, IList<AVObject> dirtyChildren) {
CollectDirtyChildren(node,
dirtyChildren,
new HashSet<AVObject>(new IdentityEqualityComparer<AVObject>()),
new HashSet<AVObject>(new IdentityEqualityComparer<AVObject>()));
}
/// <summary>
/// Returns true if the given object can be serialized for saving as a value
/// that is pointed to by a AVObject.
/// </summary>
private static bool CanBeSerializedAsValue(object value) {
return DeepTraversal(value, yieldRoot: true)
.OfType<AVObject>()
.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);
}
}
}
/// <summary> /// <summary>
/// Adds a task to the queue for all of the given objects. /// Adds a task to the queue for all of the given objects.
/// </summary> /// </summary>
@ -1089,8 +1056,7 @@ string propertyName
/// <returns>A AVRelation for the key.</returns> /// <returns>A AVRelation for the key.</returns>
public AVRelation<T> GetRelation<T>(string key) where T : AVObject { public AVRelation<T> GetRelation<T>(string key) where T : AVObject {
// All the sanity checking is done when add or remove is called. // All the sanity checking is done when add or remove is called.
AVRelation<T> relation = null; TryGetValue(key, out AVRelation<T> relation);
TryGetValue(key, out relation);
return relation ?? new AVRelation<T>(this, key); return relation ?? new AVRelation<T>(this, key);
} }
@ -1422,10 +1388,11 @@ string propertyName
return false; return false;
} }
static Stack<Batch> BatchObjects(IEnumerable<AVObject> avObjects) { static Stack<Batch> BatchObjects(IEnumerable<AVObject> avObjects, bool containsSelf) {
Stack<Batch> batches = new Stack<Batch>(); Stack<Batch> batches = new Stack<Batch>();
// 根节点作为第一批次,不适用依赖引用的判断规则 if (containsSelf) {
batches.Push(new Batch(avObjects)); batches.Push(new Batch(avObjects));
}
IEnumerable<object> deps = from avObj in avObjects select avObj.estimatedData.Values; IEnumerable<object> deps = from avObj in avObjects select avObj.estimatedData.Values;
do { do {