Skip to content

fix: respond to date and vote changes before refreshing Discord - #11

Merged
joshchen-dev merged 2 commits into
mainfrom
claude/great-shannon-b4y5vi
Oct 6, 2026
Merged

joshchen-dev merged 2 commits into
mainfrom
claude/great-shannon-b4y5vi

Conversation

@joshchen-dev

@joshchen-dev joshchen-dev commented Oct 6, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • The problem: confirming or cancelling a date on the web, and voting or changing a date in Discord, edited the Discord timetable message inside the request. Discord rate-limits message edits per channel, so repeated clicks queued behind DiscordGo's rate limiter and each request waited seconds.
  • The fix: changes now commit to PostgreSQL and respond immediately. A new pollRefresher updates the Discord message in the background.
    • Changes to the same poll within 750 ms are merged into one edit.
    • The edit always renders the latest database state, so merging never shows stale data.
    • A change that arrives after a refresh has started schedules another refresh.
  • Crash safety:
    • Only the "re-render this message" step waits in memory; the change itself is already in PostgreSQL.
    • On startup, the scheduler queues a refresh for every published, open poll, through the new Store.PublishedOpenPollIDs. A refresh lost to a crash or restart is repaired within a second of coming back up.
    • No durable message queue is needed, because each refresh can be fully recomputed from stored state.
  • Bumps the version to v0.0.11.

Verification

  • New TestPollRefresherCoalescesBursts: five rapid queues on one poll give one refresh, other polls refresh independently, and a later change triggers another refresh.
  • New TestPublishedOpenPollIDs: lists only open polls with a Discord message, excluding unpublished and closed ones.
  • go test ./... with TEST_DATABASE_URL (PostgreSQL 16), go test -race ./internal/discord, go vet ./....

Confirming, cancelling, or voting edited the Discord timetable message
inside the request. Discord limits message edits per channel, so rapid
clicks queued behind its rate limiter and each request waited seconds.
Changes now commit to PostgreSQL and respond immediately; the message
is refreshed in the background, and changes within 750 ms are merged
into one edit that renders the latest database state.
A background refresh lost to a crash or restart left the Discord message
stale until the next change. On startup the scheduler now queues a
refresh for every published, open poll, rebuilding each message from
PostgreSQL.
@joshchen-dev
joshchen-dev merged commit c0bfa0f into main Oct 6, 2026
1 check passed
@joshchen-dev
joshchen-dev deleted the claude/great-shannon-b4y5vi branch October 6, 2026 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant