chore: SaveAll/DeleteAll
parent
4bb16ce423
commit
d084c92721
|
@ -349,18 +349,18 @@ namespace LeanCloud.Storage {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<List<LCObject>> SaveAll(List<LCObject> objectList) {
|
public static async Task<List<LCObject>> SaveAll(IEnumerable<LCObject> objects) {
|
||||||
if (objectList == null) {
|
if (objects == null) {
|
||||||
throw new ArgumentNullException(nameof(objectList));
|
throw new ArgumentNullException(nameof(objects));
|
||||||
}
|
}
|
||||||
foreach (LCObject obj in objectList) {
|
foreach (LCObject obj in objects) {
|
||||||
if (LCBatch.HasCircleReference(obj, new HashSet<LCObject>())) {
|
if (LCBatch.HasCircleReference(obj, new HashSet<LCObject>())) {
|
||||||
throw new ArgumentException("Found a circle dependency when save.");
|
throw new ArgumentException("Found a circle dependency when save.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Stack<LCBatch> batches = LCBatch.BatchObjects(objectList, true);
|
Stack<LCBatch> batches = LCBatch.BatchObjects(objects, true);
|
||||||
await SaveBatches(batches);
|
await SaveBatches(batches);
|
||||||
return objectList;
|
return objects.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Delete() {
|
public async Task Delete() {
|
||||||
|
@ -371,12 +371,11 @@ namespace LeanCloud.Storage {
|
||||||
await LCApplication.HttpClient.Delete(path);
|
await LCApplication.HttpClient.Delete(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task DeleteAll(List<LCObject> objectList) {
|
public static async Task DeleteAll(IEnumerable<LCObject> objects) {
|
||||||
if (objectList == null || objectList.Count == 0) {
|
if (objects == null || objects.Count() == 0) {
|
||||||
throw new ArgumentNullException(nameof(objectList));
|
throw new ArgumentNullException(nameof(objects));
|
||||||
}
|
}
|
||||||
IEnumerable<LCObject> objects = objectList.Where(item => item.ObjectId != null);
|
HashSet<LCObject> objectSet = new HashSet<LCObject>(objects.Where(item => item.ObjectId != null));
|
||||||
HashSet<LCObject> objectSet = new HashSet<LCObject>(objects);
|
|
||||||
List<Dictionary<string, object>> requestList = objectSet.Select(item => {
|
List<Dictionary<string, object>> requestList = objectSet.Select(item => {
|
||||||
string path = $"/{LCApplication.APIVersion}/classes/{item.ClassName}/{item.ObjectId}";
|
string path = $"/{LCApplication.APIVersion}/classes/{item.ClassName}/{item.ObjectId}";
|
||||||
return new Dictionary<string, object> {
|
return new Dictionary<string, object> {
|
||||||
|
|
Loading…
Reference in New Issue