fix(data): serialize portfolio mutations before rows

This commit is contained in:
2026-06-02 10:32:13 +03:00
parent edf40c9a09
commit a20da4b1a0
8 changed files with 379 additions and 238 deletions
@@ -31,7 +31,12 @@ public sealed class DeleteSessionHandler(
await using var connection = await dataSource.OpenConnectionAsync(ct);
await using var transaction = await connection.BeginTransactionAsync(ct);
// 1. Lock the session before any linked portfolio card and verify group manager.
// 1. Use the database mutation order before locking the session or linked portfolio cards.
await connection.ExecuteAsync(
"SELECT pg_advisory_xact_lock(20260530, 108)",
transaction: transaction);
// 2. Lock the session before any linked portfolio card and verify group manager.
var session = await connection.QuerySingleOrDefaultAsync<DeleteSessionInfoDto>(
"""
SELECT s.title AS Title,
@@ -63,7 +68,7 @@ public sealed class DeleteSessionHandler(
return new DeleteSessionResult(false, "Только owner или co-GM может удалять сессию.", null, null, null, false, 0);
}
// 2. Unpublish a linked portfolio card before its required session link cascades away.
// 3. Unpublish a linked portfolio card before its required session link cascades away.
await connection.ExecuteAsync(
"""
UPDATE portfolio_games pg
@@ -77,7 +82,7 @@ public sealed class DeleteSessionHandler(
new { command.SessionId },
transaction);
// 3. Delete session
// 4. Delete session
await connection.ExecuteAsync("DELETE FROM sessions WHERE id = @Id", new { Id = command.SessionId }, transaction);
var remainingInTopic = session.ThreadId.HasValue