Fix: Stats showing stale unique visitors count when views are updated #24356
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #24114
While I was not able to reproduce the issue mentioned here #24114 and while it seems it's not a specific issue related to the app because of this Automattic/jetpack#42176 I noticed that the login for updating stats with
mostRecentChartData
was too restrictive. Even when new API data was available, the existing code would sometimes keep using old cached data due to specific date matching requirements.So, I revised the conditional logic that now prioritizes using the newest data by simplifying the conditions and always choosing the most recent data available. In this way, we ensure that both views and unique visitors metrics update simultaneously when new data arrives from the API.
Testing
Verified that both views and unique visitors data update synchronously when new stats data is fetched. Please, also check that this change does not introduce any regression, like reintroducing this issue #19688
Regression Notes
Potential unintended areas of impact
What I did to test those areas of impact (or what existing automated tests I relied on)
What automated tests I added (or what prevented me from doing so)
PR submission checklist:
RELEASE-NOTES.txt
if necessary.Testing checklist: