private sealed record BulkTask( ICommandBus Bus, int JobIndex, BulkUpdateJob CommandJob, BulkUpdateAssets Command, ConcurrentBag <BulkUpdateResultItem> Results ) { }
private sealed record BulkTask( ICommandBus Bus, string Schema, int JobIndex, BulkUpdateJob CommandJob, BulkUpdateContents Command, ConcurrentBag <BulkUpdateResultItem> Results ) { }
public void Should_serialize_type() { var source = new BulkUpdateJob { Type = BulkUpdateType.ChangeStatus }; var serialized = source.ToJson(); Assert.Contains("\"type\": \"ChangeStatus\"", serialized, StringComparison.Ordinal); }
private async Task <DomainId?> FindIdAsync(Context context, string schema, BulkUpdateJob job) { var id = job.Id; if (id == null && job.Query != null) { job.Query.Take = 1; var existing = await contentQuery.QueryAsync(context, schema, Q.Empty.WithJsonQuery(job.Query)); if (existing.Total > 1) { throw new DomainException(T.Get("contents.bulkInsertQueryNotUnique")); } id = existing.FirstOrDefault()?.Id; } return(id); }
private async Task <Guid?> FindIdAsync(Context context, string schema, BulkUpdateJob job) { var id = job.Id; if (id == null && job.Query != null) { job.Query.Take = 1; var existing = await contentQuery.QueryAsync(context, schema, Q.Empty.WithJsonQuery(job.Query)); if (existing.Total > 1) { throw new DomainException("More than one content matches to the query."); } id = existing.FirstOrDefault()?.Id; } return(id); }
public static async Task ImportAsync(this ISession session, IImportSettings setting, ILogger log, IEnumerable <DynamicData> datas) { var contents = session.Contents(setting.Schema); var totalWritten = 0; using (var logLine = log.WriteSameLine()) { var keyField = setting.KeyField; var update = new BulkUpdate { Jobs = new List <BulkUpdateJob>(), DoNotScript = false, DoNotValidate = false, Publish = !setting.Unpublished }; const string op = "eq"; foreach (var batch in datas.Batch(50)) { update.Jobs.Clear(); foreach (var data in batch) { var job = new BulkUpdateJob { Data = data, }; if (!string.IsNullOrWhiteSpace(keyField)) { if (!data.TryGetValue(keyField, out var temp) || temp is not JObject obj || !obj.TryGetValue("iv", StringComparison.Ordinal, out var value)) { throw new InvalidOperationException($"Cannot find key '{keyField}' in data."); } job.Query = new { filter = new { path = $"data.{keyField}.iv", op, value, } }; job.Type = BulkUpdateType.Upsert; } else { job.Type = BulkUpdateType.Create; } update.Jobs.Add(job); } var result = await contents.BulkUpdateAsync(update); var error = result.Find(x => x.Error != null)?.Error; if (error != null) { throw new SquidexManagementException <ErrorDto>(error.Message, error.StatusCode, null, null, error, null); } totalWritten += update.Jobs.Count; logLine.WriteLine("> Imported: {0}.", totalWritten); } } log.WriteLine("> Imported: {0}. Completed.", totalWritten); }