Stats doesn't roll over to the new day at the site's midnight
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 38/100
Línea de trabajo
Start with StatsViewModel, StatsDateRange, TodayCardViewModel, StatsService, and TodayCard.currentDateText, then trace how preset ranges, Today card loads, and cache expiry use the current date. Implement the site's time zone day monitor and the rollover and cache changes described in the issue, using an injectable clock for tests. Done means the listed unit tests pass and Stats updates across the site's midnight, including when a load is in progress or the app resumes.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
From Claude:
Stats doesn't notice when the site's day changes. If Stats is open at midnight in the site's time zone, it keeps showing the old day until the user picks a new range or pulls to refresh.
What happens
- The Today card shows yesterday's totals under today's date. This affects the card on the Traffic tab and the one on the My Site dashboard.
- Ranges like "Last 7 days" or "This month" stop moving. After midnight they still end yesterday, so the newest day never appears.
- A load that is running at midnight can be cached forever with yesterday's partial totals. This one lasts for the rest of the app session, not just until the next reload.
PR #26410 made one case easier to hit. Before it, the chart sent an unchanged selection to every card when it finished loading. That made the Today card work out "today" again, and if midnight had passed, it switched to the new day. The update was a bug (it restarted loads that were still running), and #26410 removed it. Now, if the Today card's first load is still running when the site's midnight passes, the card finishes with yesterday's numbers (reported by @crazytonyli in this review).
Root Cause
Each date range is worked out once from the current time, when it's created. Nothing in JetpackStats watches for the day to change.
StatsViewModelbuilds its preset range ininitand only changes it when the user does.TodayCardViewModelworks out "today" again only when itsdateRangeis assigned. The dashboard card also does this inrefreshIfNeeded(), but only when it appears, and only when no load is running.StatsServicedecides whether to cache a response forever or for 30 seconds after the response arrives (intervalContainsCurrentDateingetSiteStatsandgetTopListData). A request for "today" sent at 23:59:58 that comes back at 00:00:01 counts as a past day, so the cache keeps its partial totals with no expiry.TodayCard.currentDateTextformatsDate()in the device's time zone, so the header can show a different day from the data even without a rollover.
Proposed fix
1. Detect a new day in the site's time zone
Add a small @MainActor monitor that reports when the day changes in context.timeZone:
- Wait until the site's next midnight (
calendar.dateInterval(of: .day, for: now).end). - Also check after
UIApplication.significantTimeChangeNotificationand when the app returns to the foreground, because timers don't run while the app is suspended. - Report a change only when the site's day really differs from the last one it saw, so these extra checks don't cause extra reloads.
- Take the clock as a parameter so tests can control it.
NSCalendarDayChanged won't work, because it fires at the device's midnight.
2. Move preset ranges forward
Add StatsDateRange.rolledOver(now:):
- If the range came from a preset (
preset != nil), work it out again fornowand keep the comparison setting. Navigating clearspreset, so ranges the user moved to stay put, and so do custom ranges. - Let
update(preset:)/updating(preset:)takenow:instead of always using.now, so tests can control time.
StatsViewModel assigns the rolled-over selection when the monitor reports a new day. For preset ranges that's a real change, so the guard from #26410 lets it through and every card reloads.
3. Always roll the Today card over
The Today card always shows today, even when the main range doesn't move (for example, a custom range). So:
StatsViewModelandStatsTodayCardControllerboth tell the Today card about a new day directly. The card works out "today" again and reloads, even if a load is running. The currentisLoadingcheck inrefreshIfNeeded()would skip that.- When a load finishes, the card checks that the range it loaded still contains
currentDate(). If it doesn't, it reloads instead of showing the old data. This covers a load that started just before midnight.
4. Classify cache entries when the request is sent
In StatsService.getSiteStats and getTopListData, run intervalContainsCurrentDate before the request goes out. A response for an interval that was current when it was requested then gets the 30-second expiry, even if it arrives after midnight. Check getWordAdsStats (dateIsToday) for the same pattern.
5. Header date
Format TodayCard.currentDateText from the start of the loaded range, using the site's time zone.
Open questions
- Selected bar or subrange: keep it if it still falls inside the new range, otherwise clear it? (Suggested default.)
- Detail screens (
AuthorStatsView,UTMMetricStatsView,PostStatsView,StandaloneChartCard) keep their own copy of the range. Suggest leaving them out at first. They're usually open only briefly, and pull-to-refresh is enough there.
Test plan
- Unit tests with a clock the test controls:
- The monitor fires at the site's midnight, not the device's, and fires once per day.
-
rolledOver(now:)moves preset ranges and leaves navigated and custom ranges alone. - A Today card load running at midnight is replaced by a load for the new day, and yesterday's data never shows.
- A response for a current interval that arrives after midnight is cached with the 30-second expiry, not forever.
- On a simulator: set the test site's time zone so its midnight is two minutes away, leave Stats open on "Last 7 days", and check that the Today card, the chart and the top lists all move to the new day without any interaction. Repeat with the app in the background across midnight, and with a custom range selected.
Related issues
- #26410
- Lenguaje dominante
- Swift
- Estrellas
- 3.9k
- Forks
- 1.2k
- Merge medio
- 1 d 23 h
- PR fusionados (30 d)
- 136
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de wordpress-mobile/WordPress-iOS
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
wordpress-mobile/WordPress-iOS#26423 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[Pri] Low [Status] Ready for Dev [Type] Bug /Me
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
wordpress-mobile/WordPress-iOS#26279 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[Pri] Low [Status] Ready for Dev [Type] Bug Share Extension
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
wordpress-mobile/WordPress-iOS#26276 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[Pri] Low [Status] Ready for Dev [Type] Bug Blogging Prompts Notifications
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
wordpress-mobile/WordPress-iOS#26256 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[Status] Ready for Dev [Type] Bug Reader
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
wordpress-mobile/WordPress-iOS#26254 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de wordpress-mobile/WordPress-iOS
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
-
🎉 Add RemoteCrabAbierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 70/100
jaywcjlove/awesome-mac#4999 ·
Los mantenedores suelen responder en 1 día
-
[Type] Bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
wordpress-mobile/GutenbergKit#940 ·
Los mantenedores suelen responder en 1 día
-
pending-maintainer-response pending-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
aws-amplify/amplify-swift#4423 ·
Los mantenedores suelen responder en 2 días
-
tests
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
erkamyaman/unslop-anything#80 ·
Los mantenedores suelen responder en 1 día