perf(notifications): use conditional requests for the notifications list - #3103
Open
joshfree wants to merge 2 commits into
Open
perf(notifications): use conditional requests for the notifications list#3103joshfree wants to merge 2 commits into
joshfree wants to merge 2 commits into
Conversation
Send If-None-Match / If-Modified-Since validators on the notifications list request and cache the previous response per account. When GitHub responds 304 Not Modified (nothing changed since the last poll) the cached list is returned without transferring or re-parsing the full body; a 304 also does not count against the primary rate limit. Refs gitify-app#3101
Member
|
i have a feeling the explicit
we'll need to test how this PR handles situations like this |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes part of #3101 (Improvement 2 of 3).
Problem
The notifications list is requested with caching disabled and no validators
(
listNotificationsForAuthenticatedUserinclient.tssetsCache-Control: no-cache), so the full list body is transferred and re-parsedon every poll even when nothing has changed.
Change
Cache the previous notifications-list response per account and send conditional
request validators (
If-None-Matchfrom the storedETag, falling back toIf-Modified-SincefromLast-Modified). When GitHub responds304 Not Modified, the cached list is returned without transferring or re-parsing thebody. A
304also does not count against the primary rate limit.Notes:
RequestErrorwithstatus === 304for an unchangedconditional request, so that is caught and mapped back to the cached list.
Cache-Control: no-cacheis retained to force revalidation rather than servea stale locally-cached response; the validators are added alongside it.
Tests
Added coverage in
client.test.tsfor: replaying the storedETagasIf-None-Matchon the next poll, and returning the cached list on a304forboth the single-page and paginated paths.