Skip to content

Fix race condition in ViewCountService#192

Open
hishamco wants to merge 1 commit intomainfrom
view-count-race-condition
Open

Fix race condition in ViewCountService#192
hishamco wants to merge 1 commit intomainfrom
view-count-race-condition

Conversation

@hishamco
Copy link
Member

Fixes #191

/cc @MikeAlhayek

{
Guard.ArgumentNotNull(contentItem, nameof(contentItem));

await _semaphore.WaitAsync();
Copy link
Contributor

@MikeAlhayek MikeAlhayek Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your service is registered as scoped, so it won't block others from creating raise condition. And if you make it singleton, it will cause a bottleneck on a busy site.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So how your approach fixing the issue?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not write to the document directly. It writes to tables that are dedicated to tracking views. So the more the view, you increase the insert which isn't going to block or cause ease condition to updating the same content item.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any suggestions in this particular case after I register it as a singleton?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hishamco hishamco closed this Jan 18, 2026
@hishamco hishamco reopened this Jan 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Views Counter raise condition

2 participants