fix(data): align portfolio mutation lock order

This commit is contained in:
2026-06-01 20:23:43 +03:00
parent 2b725708ef
commit a28b75dd5b
8 changed files with 220 additions and 22 deletions
+3 -1
View File
@@ -6,7 +6,9 @@ var postgres = builder.AddPostgres("postgres")
var bot = builder.AddProject<Projects.GmRelay_Bot>("bot")
.WithReference(postgres)
.WaitFor(postgres);
.WaitFor(postgres)
.WithHttpEndpoint(port: 8081, targetPort: 8081, name: "health")
.WithHttpHealthCheck("/health", endpointName: "health");
builder.AddProject<Projects.GmRelay_DiscordBot>("discord")
.WithReference(postgres)
@@ -45,6 +45,19 @@ public sealed class DiscordDeleteSessionHandler(
}
await using var transaction = await connection.BeginTransactionAsync(cancellationToken);
_ = await connection.QuerySingleOrDefaultAsync<Guid?>(
"""
SELECT s.id
FROM sessions s
JOIN game_groups g ON g.id = s.group_id
WHERE s.id = @SessionId
AND g.platform = 'Discord'
AND g.external_group_id = @GuildId
FOR UPDATE OF s
""",
new { SessionId = sessionId, GuildId = guildId },
transaction);
await connection.ExecuteAsync(
"""
UPDATE portfolio_games pg
@@ -31,7 +31,7 @@ public sealed class DeleteSessionHandler(
await using var connection = await dataSource.OpenConnectionAsync(ct);
await using var transaction = await connection.BeginTransactionAsync(ct);
// 1. Fetch session and verify group manager.
// 1. Lock the session before any linked portfolio card and verify group manager.
var session = await connection.QuerySingleOrDefaultAsync<DeleteSessionInfoDto>(
"""
SELECT s.title AS Title,
@@ -49,6 +49,7 @@ public sealed class DeleteSessionHandler(
) AS CanManage
FROM sessions s
WHERE s.id = @SessionId
FOR UPDATE OF s
""",
new { command.SessionId, Platform = command.User.Platform.ToString(), ExternalUserId = command.User.ExternalUserId }, transaction);