Skip to content
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

Performance Card Unable to Fetch Cached Site Summary Data When Site and Device Timezone differs #14462

Open
hafizrahman opened this issue Nov 20, 2024 · 1 comment
Labels
feature: dashboard Related to the My Store dashboard priority: low Not many people are affected or there’s a workaround, etc. type: bug A confirmed bug.

Comments

@hafizrahman
Copy link
Contributor

hafizrahman commented Nov 20, 2024

This issue is discovered when testing #14438 and is affecting trunk too.

The trigger is:

  1. Have a test site that has a timezone completely different from the device timezone. In my case, test site is UTC-6 while device is UTC+7
  2. Start app, login to site freshly (can switch from another site to it),
  3. Switch to This Year in Performance card,
  4. Confirm that the data is shown correctly,
  5. Immediately rebuild app,
  6. Check Performance card again, confirm that the visitors and conversion data are not shown.

Expected: Performance card should be able to show the cached data that's downloaded on step 3-4.

The issue does not seem to appear when site and device timezone are the same, but I can't really tell how different the timezones should be to trigger the issue. So, this might be an edge case as I don't think we've heard report about it.

Investigation.

This is what I can investigate so far.

When logging in to a new site for the first time, as DashboardViewModel is being initialized, it also initializesself.storePerformanceViewModel.

StorePerformanceViewModel then initializes its siteTimezone: TimeZone = .siteTimezone, which calls this:

extension TimeZone {
/// Returns the TimeZone using the timezone configured in the current website
///
static var siteTimezone: TimeZone {
#if !os(watchOS)
return ServiceLocator.stores.sessionManager.defaultSite?.siteTimezone ?? .current

In my test, defaultSite is still nil (perhaps because it's still early in the process), so StorePerformanceViewModel uses device timezone instead (UTC+7 in my case). The part that sets the predicate for fetching cached data then uses this timezone:

let formattedDateString: String = {
let date = timeRange.latestDate(currentDate: currentDate, siteTimezone: siteTimezone)
return StatsStoreV4.buildDateString(from: date, timeRange: .today)
}()
let predicate = NSPredicate(format: "siteID = %ld AND period == %@ AND date == %@",
siteID,
timeRange.summaryStatsGranularity.rawValue,
formattedDateString)

The card then fetches and saves "Day" time range data by default. As we change the time range "This Year", the app then proceeds to fetch and save it, still using the device timezone. The data is saved with "2024-12-31" in its date value.

Now, on Step 5 after the app is rebuilt, defaultSite is now available. As StorePerformanceViewModel is recreated, it now uses the site's timezone (UTC-6 in my case). I can't figure out why yet, but this causes the formattedDateString in summaryStatsResultsController above to be off by one, "2025-01-01". As the saved data's value is "2024-12-31", the app now is unable to show the cached data.

@hafizrahman hafizrahman added feature: dashboard Related to the My Store dashboard type: bug A confirmed bug. labels Nov 20, 2024
@dangermattic
Copy link
Collaborator

dangermattic commented Nov 20, 2024

Thanks for reporting! 👍

@hafizrahman hafizrahman changed the title Performance Card Unable to Fetch Cached Site Summary Data When Timezone differs Performance Card Unable to Fetch Cached Site Summary Data When Site and Device Timezone differs Nov 20, 2024
@hafizrahman hafizrahman added the priority: low Not many people are affected or there’s a workaround, etc. label Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: dashboard Related to the My Store dashboard priority: low Not many people are affected or there’s a workaround, etc. type: bug A confirmed bug.
Projects
None yet
Development

No branches or pull requests

2 participants