Skip to content

Views Counter raise condition #191

@MikeAlhayek

Description

@MikeAlhayek

@hishamco I came across this on LinkedIn and took a look at the code out of curiosity. One thing to be aware of is that this approach can fail when more than one user is viewing the same article at the same time. There’s a race condition between updates.

This becomes an even bigger issue when you have many concurrent readers and someone editing the article at the same time—an editor could potentially lose their changes while others are viewing the content due to the same race condition.

In my own implementation, I also track views, but I handle it differently by using a ShapeTableProvider and executing a raw SQL update to increment the counter atomically, which avoids these concurrency issues.

Just wanted to share this in case it’s helpful.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions