Gracefully disable useRequest()
cache when no request is active
#2009
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.
Description
This PR allows the
recordsForUpload()
function inpackages/server/src/arpa_reporter/services/records.js
to gracefully fall back to a cache-less implementation when no request is active. Generally, theuseRequest()
function helpsrecordsForUpload()
implement request-scoped memoization (specifically, for avoiding multiple reads of the same file in the same request), but it causes workflows that are not triggered by a request to fail whenrecordsForUpload()
is called.With these changes, when
recordsForUpload()
is called outside the scope of a request, it falls back to a function-local, empty object (which will be GC'd after the function returns). This is admittedly a bit of a hack, but I think it's worth the tradeoffs. If it turns out that, even in a task-based environment, memoization is definitely necessary, we'll have to come up with an alternative mechanism for scoping a memoization cache to a per-task-message lifecycle.Screenshots / Demo Video
Testing
Automated and Unit Tests
Manual tests for Reviewer
Checklist