You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR significantly improves the performance of the offline session
exporter. It addresses concerns that the "Record offline" function was
taking too long (up to 10s) and if sessions get bigger (eg with flu) the
threshold to cause timeouts will be reached, and it will not be possible
for these spreadsheets to be generated by SAIS teams.
While most sessions will have around 1,000 patients, community clinic
sessions could potentially contain up to 60,000 patients. For this special
case, we may need to implement a background job in the future to handle the
export asynchronously, but hopefully, this optimisation should handle the
vast majority of use cases.
Key improvements:
- Added comprehensive eager loading for all required associations
- Cached vaccination records in memory with `to_a` to avoid repeated DB calls
- Memoise `clinic_name_values`
Performance impact based on 1236 patient sessions:
- Total time: 6.45s → 2.47s (62% faster)
- SQL queries: 10,649 → 77 (99.3% reduction)
- SQL time: 1.83s → 0.30s (84% faster DB time)
The most significant improvement came from eliminating repeated queries for
parent relationships, location names, and programme lookups which were
previously causing thousands of separate database calls.
0 commit comments