medium10 pts · first answer countsdatabasesconcurrencysql
Page view counter loses counts
This code loses views under load. What is the fix?
const { views } = await db.one('SELECT views FROM posts WHERE id = $1', [id])
await db.none('UPDATE posts SET views = $1 WHERE id = $2', [views + 1, id])Discussion 0
Join free to post in the discussion.
Related questions
- Stopping SQL injectionBackend Developer
- Purpose of a database indexBackend Developer
- Rows returned by a LEFT JOINBackend Developer
- What a foreign key enforcesBackend Developer
- Atomicity in a money transferBackend Developer
- COUNT and AVG with NULLsBackend Developer
- Filtering grouped resultsBackend Developer
- Duplicate emails despite a checkBackend Developer