Summary
New photo order is derived from count() + 1, which is race-prone. Concurrent uploads can read the same count and write duplicate order values, producing unstable feed ordering.
Why this matters
- Feed order becomes nondeterministic under concurrent uploads
- Duplicate order values make sort behavior depend on database implementation details
- This gets worse as usage increases
Evidence
app/db/actions.ts:117-133
Suggested fix
Replace the count-based order assignment with an atomic monotonic strategy. Options include a database sequence, ordering by created_at plus a tiebreaker, or an insert that derives the next order inside a transaction with proper locking.
Acceptance criteria
- Concurrent uploads cannot generate duplicate ordering keys
- Feed ordering is deterministic
- The chosen strategy is documented in code comments or schema notes
- Add a regression test or concurrency-focused integration check if practical
Summary
New photo order is derived from
count() + 1, which is race-prone. Concurrent uploads can read the same count and write duplicate order values, producing unstable feed ordering.Why this matters
Evidence
app/db/actions.ts:117-133Suggested fix
Replace the count-based order assignment with an atomic monotonic strategy. Options include a database sequence, ordering by
created_atplus a tiebreaker, or an insert that derives the next order inside a transaction with proper locking.Acceptance criteria