The total/consecutive days visited counters are updated the first time a user hits the site each day - these daily site access checks happen when we authenticate/initialize the current user.
There were two issues that caused the daily site access counter to be off:
- When using the ASP.NET MVC HtmlHelper's
RenderAction
method (which allows "subcontroller" calls), our base controller was reinitializing the current user for each RenderAction
call.
- Users were making multiple simultaneous requests to the site.
In both cases, the date checks that happen before updating those counters would always pass for the subsequent, simultaneous initializations - the database updates couldn't fire fast enough!
To fix these issues, we now:
- Store the current user in the
HttpContext.Items
collection, making it available to all parts of the request. Only one initialization needs to happen, regardless of how many "subcontroller" calls are made.
- Lock the user database record via a simple semaphore. The lock must be acquired before doing any work in the daily site access check.
The data has been fixed and we'll be monitoring how well this works. Thanks for all the input!
Also, the Enthusiast and Fanatic badges weren't as affected by this bug, because they are not yet tied to these counters - they are still checking our user history table.