Fix voting start time race condition
Build and Push Docker Image / build (push) Has been cancelled Details

Set votingStartAt to 1 minute in the past when opening/reopening rounds
or awards. This ensures voting is immediately available without the
"opens in less than a minute" message appearing due to timing differences
between when the date is set and when the page renders.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Matt 2026-02-05 17:08:09 +01:00
parent d6386be678
commit 049ac9257f
2 changed files with 7 additions and 3 deletions

View File

@ -268,7 +268,9 @@ export const roundRouter = router({
if (input.status === 'ACTIVE' && previousRound.status !== 'ACTIVE') { if (input.status === 'ACTIVE' && previousRound.status !== 'ACTIVE') {
if (previousRound.votingStartAt && previousRound.votingStartAt > now) { if (previousRound.votingStartAt && previousRound.votingStartAt > now) {
updateData.votingStartAt = now // Set to 1 minute in the past to ensure voting is immediately open
const oneMinuteAgo = new Date(now.getTime() - 60 * 1000)
updateData.votingStartAt = oneMinuteAgo
votingStartAtUpdated = true votingStartAtUpdated = true
} }
} }

View File

@ -207,9 +207,11 @@ export const specialAwardRouter = router({
} }
if (input.status === 'VOTING_OPEN' && current.status !== 'VOTING_OPEN') { if (input.status === 'VOTING_OPEN' && current.status !== 'VOTING_OPEN') {
// If no voting start date, or if it's in the future, set it to now // If no voting start date, or if it's in the future, set it to 1 minute ago
// to ensure voting is immediately open (avoids race condition with page render)
if (!current.votingStartAt || current.votingStartAt > now) { if (!current.votingStartAt || current.votingStartAt > now) {
updateData.votingStartAt = now const oneMinuteAgo = new Date(now.getTime() - 60 * 1000)
updateData.votingStartAt = oneMinuteAgo
votingStartAtUpdated = true votingStartAtUpdated = true
} }
} }