Let the database decide whether a reaction is already there

Fixkamo-shared-library
Shipped
August 27, 2026 at 1:59 AM UTC
Author
kamo
Commit
02b6153

The unique constraint on (message, member, emoji) was doing nothing useful. A read-then-save loses the race with the member's own second click, and catching the resulting violation is worse than useless: it surfaces at flush, which is normally after the catch block, and by then the transaction is already marked rollback-only — so the "safe under a double-click" the constraint was there for would have arrived as a 500. insertIfAbsent is an ON CONFLICT DO NOTHING upsert keyed on that constraint, which is the only place the question can be answered atomically.

All changes

Like what you see shipping?

Every one of these updates lands in your workspace automatically. Start free and watch it grow week after week.

Start Free ForeverView Pricing