Skip to content

Conversation

@dgboss
Copy link
Collaborator

@dgboss dgboss commented Nov 18, 2025

I moved the logic for the 'start date' of the app from App.tsx to dataSliceUtils.ts which will facilitate testing with dates in the past. ie. To load historical data in the app set today = Datetime.fromISO("2025-7-11") in dataSliceUtils.ts.

If you have your .env file setup to use your dev API instance you can either monitor logs or set breakpoints in the fba.py router module to ensure that API requests are made as per the criteria listed below.

Data cached with a 12 hour TTL:

  • fire centres (for the drop-down)

Data we cache for the entire province for TDY and TMR:

  • Fire shape area, fire shape area detail, hfi and tpi data - We follow a cache first paradigm when accessing this data to avoid unnecessary API requests. Cache is updated from API requests when ever data is stale (ie the run parameters cached with this data don't match the most recent run parameters for TDY and TMR).
  • SFMS Run Parameters for TDY and TMR. We follow an API first paradigm and check for updated run parameters with every change of TDY/TMR. We could potentially consider a TTL of 1 hour or something like that instead of hitting the API everytime.

Expected behaviour while online:

First time launching the app:

  • App requests Fire Centres data (for the drop-down menu)
  • App requests SFMS run parameters for TDY and TMR
  • App requests fire shape area, fire shape area detail, hfi and tpi data
  • All data is cached

Toggling TDY - TMR should trigger a request for SFMS run parameters every time while online. If we have cached fire shape area, fire shape area detail, hfi and tpi data associated with the most recent run parameters, no api request is made for these data. If cached fire shape area, fire shape area detail, hfi and tpi data are stale we re-fetch from the API, cache the latest values and update redux state.

Subsequent app launches:

  • App requests Fire Centres if cached data is > 12 hours old
  • App requests SFMS run parameters for TDY and TMR
  • If cached fire shape area, fire shape area detail, hfi and tpi data are not stale they are not requested

Expected behaviour after transitioning from online to offline:

  • The TDY/TMR button does not trigger an API request, data is read from existing state
  • No Fire Centres request, even if data is > 12 hours old
  • No requests for fire shape area, fire shape area detail, hfi and tpi data

Expected behaviour after transitioning from offline to online:

  • The TDY/TMR button triggers an API request for runParameters
  • Requests for fire shape area, fire shape area detail, hfi and tpi data are only made if cached data is stale

Expected behaviour when launching while offline:

  • Login screen is not presented
  • No API requests attempted
  • Data from cache should be loaded into redux state and app should function

Expected behaviour when offline overnight:

  • No API requests attempted
  • Data from cache should be loaded into redux state and app should function
  • The cache has no concept of TDY/TMR but has everything keyed by date. So yesterday's TMR data should seamlessly display as TDY's data. No data for TMR will be available.

There is nothing in the UI yet to indicate that data is stale or that we're offline.

Closes: #4741

Test Links:

Landing Page
MoreCast
Percentile Calculator
C-Haines
FireCalc
FireCalc bookmark
Auto Spatial Advisory (ASA)
HFI Calculator
SFMS Insights
Fire Watch

@codecov
Copy link

codecov bot commented Nov 18, 2025

Codecov Report

❌ Patch coverage is 83.47639% with 77 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.09%. Comparing base (d81ec21) to head (f2be8a4).

Files with missing lines Patch % Lines
mobile/asa-go/src/App.tsx 0.00% 16 Missing and 3 partials ⚠️
mobile/asa-go/src/api/fbaAPI.ts 6.25% 15 Missing ⚠️
api/app/routers/fba.py 83.75% 9 Missing and 4 partials ⚠️
mobile/asa-go/src/utils/dataSliceUtils.ts 80.95% 12 Missing ⚠️
mobile/asa-go/src/slices/runParametersSlice.ts 92.64% 4 Missing and 1 partial ⚠️
mobile/asa-go/src/utils/hfiStatsUtils.ts 0.00% 5 Missing ⚠️
mobile/asa-go/src/slices/dataSlice.ts 97.18% 2 Missing ⚠️
mobile/asa-go/src/slices/fireCentersSlice.ts 90.47% 2 Missing ⚠️
mobile/asa-go/src/components/map/ASAGoMap.tsx 80.00% 1 Missing ⚠️
...-go/src/components/profile/FireZoneUnitSummary.tsx 75.00% 1 Missing ⚠️
... and 2 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4902      +/-   ##
==========================================
+ Coverage   70.89%   71.09%   +0.20%     
==========================================
  Files         372      442      +70     
  Lines       15577    17251    +1674     
  Branches     1840     2168     +328     
==========================================
+ Hits        11043    12265    +1222     
- Misses       3930     4337     +407     
- Partials      604      649      +45     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dgboss dgboss requested review from brettedw and conbrad and removed request for conbrad November 25, 2025 00:52
Copy link
Collaborator

@conbrad conbrad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking really good! Just a few thoughts to consider

Copy link
Collaborator

@brettedw brettedw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an absolute beast, great job!!

Comment on lines 62 to 76
export const readFromFilesystem = async (
filesystem: FilesystemPlugin,
key: string
) => {
try {
const result = await filesystem.readFile({
path: getPath(key),
directory: Directory.Data,
encoding: Encoding.UTF8,
});
return JSON.parse(result.data as string);
} catch {
return null;
}
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if functions like this could benefit from generics in their return typing, so the return type isn't any. Not sure if you think it's worth it or not

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great idea. Done in 1710904 and f1e9ba9

@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 28, 2025

Quality Gate Passed Quality Gate passed

Issues
7 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.8% Duplication on New Code

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ASA Go: Offline data caching

4 participants