fix(cv): make initial revision atomic
This commit is contained in:
@@ -81,6 +81,12 @@ public sealed class CvVariantService : ICvVariantService
|
||||
{
|
||||
if (jobApplicationId is not null && !await CanAssociateJobAsync(ownerUserId, jobApplicationId.Value, ct))
|
||||
throw new ArgumentException("The job application is unavailable.", nameof(jobApplicationId));
|
||||
// The first save is required to obtain the generated variant id used by its initial
|
||||
// history row. Keep both saves in one relational transaction so a concurrent autosave
|
||||
// cannot slip between them and leave a created CV without version 1.
|
||||
await using var transaction = _db.Database.IsRelational()
|
||||
? await _db.Database.BeginTransactionAsync(ct)
|
||||
: null;
|
||||
var now = DateTimeOffset.UtcNow;
|
||||
var normalized = CvVariantSettingsJson.Normalize(settings);
|
||||
var variant = new CvVariant
|
||||
@@ -98,6 +104,7 @@ public sealed class CvVariantService : ICvVariantService
|
||||
await _db.SaveChangesAsync(ct);
|
||||
AppendVersion(variant, "create");
|
||||
await _db.SaveChangesAsync(ct);
|
||||
if (transaction is not null) await transaction.CommitAsync(ct);
|
||||
return variant;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user