Skip to content

Fix: Stats showing stale unique visitors count when views are updated #24356

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -318,21 +318,21 @@ private extension SiteStatsPeriodViewModel {
if mostRecentChartData == nil {
mostRecentChartData = periodSummary
} else if let mostRecentChartData,
let periodSummary,
mostRecentChartData.periodEndDate == periodSummary.periodEndDate {
let periodSummary,
mostRecentChartData.periodEndDate == periodSummary.periodEndDate {
self.mostRecentChartData = periodSummary
} else if let periodSummary, // when there is API data that has more recent API period date
let chartData = mostRecentChartData, // than our local chartData
periodSummary.periodEndDate > chartData.periodEndDate {

// we validate if our periodDates match and if so we set the currentEntryIndex to the last index of the summaryData
// fixes issue #19688
if let lastSummaryDataEntry = summaryData.last,
periodSummary.periodEndDate == lastSummaryDataEntry.periodStartDate {
} else if let periodSummary, // when there is API data that has more recent API period date than our local chartData
let chartData = mostRecentChartData {

// Always prefer newer data
if periodSummary.periodEndDate >= chartData.periodEndDate {
mostRecentChartData = periodSummary
currentEntryIndex = summaryData.count - 1
} else {
mostRecentChartData = chartData

// Update currentEntryIndex if needed
let lastIndex = summaryData.count - 1
if lastIndex >= 0 {
currentEntryIndex = min(currentEntryIndex, lastIndex)
}
}
}

Expand Down