Prevent sending statistics from blocking Specify access #7576
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, the sending of statistics to the statistics server happens as a part of the frontend fetching the general System Information:
specify7/specifyweb/frontend/js_src/lib/components/InitialContext/systemInfo.ts
Lines 58 to 112 in 9ebd355
Because there is data from the System Information that is required for the immediate functionality and behavior of some components, the endpoint was part of Specify's "Initial Context".
All endpoints which are considered essential (i.e., must be called for normal frontend operation), are a part of this Initial Context, which blocks access to the Specify application until all endpoints have been resolved.
specify7/specifyweb/frontend/js_src/lib/components/InitialContext/index.ts
Lines 68 to 91 in 9ebd355
specify7/specifyweb/frontend/js_src/lib/components/Core/ContextLoader.tsx
Lines 20 to 43 in 9ebd355
This caused problems when the Specify statistics server was not sending responses back to Specify clients, which resulted in the requests eventually timing out.
The entire time the Specify frontend was waiting on the statistics server to send a response, the user would be blocked from the application.
Because sending statistics is not vital to the application, I've implemented a "Secondary Context": a set of endpoints that Specify will call after fetching the initial context, and that will not block access to the frontend while being resolved.
I removed the sending of statistics from the fetching of the System Information and defined a new Promise on the frontend to handle sending statistics.
Checklist
self-explanatory (or properly documented)
Testing instructions
I tested this by artificially injecting some delay in the resolution of the new statistics endpoint.
Screen.Recording.2025-12-01.at.10.42.18.AM.mov
You can use the code from the above video as a template in 1e6b59f. The stats endpoint should be now be called ~5 seconds after the stats promise is awaited.
When testing interference with Initial Context, you can uncomment the stats endpoint in the list of Initial Context endpoints:
specify7/specifyweb/frontend/js_src/lib/components/InitialContext/index.ts
Line 118 in 1e6b59f
Disable cachecheckbox in Chrome Dev Tools. Request caching will be disabled as long as Dev Tools is open)