KamoCRM

Let the database decide whether a reaction is already there

Fixkamo-shared-library
Shipped
27 ஆகஸ்ட், 2026 அன்று 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?

All of it arrives in your workspace on its own. Start on the free plan and read this page again in a month.

Start Free ForeverView Pricing