perf(notifications): use conditional requests for the notifications list - #3103
perf(notifications): use conditional requests for the notifications list#3103joshfree 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
|
i have a feeling the explicit
we'll need to test how this PR handles situations like this |
|
I dug into this one empirically, because the "quirky behavior" I half-remembered turned out to be real, measurable, and unfortunately fatal for the ETag half of this approach. The notifications endpoints return a degenerate ETag. Measured with the exact headers Octokit sends (
Since this PR prefers the stored ETag over
Also verified while testing: Given that, I don't think this is worth the correctness surface as-is. I've opened #3116 implementing improvement 3 ( |
|
Really appreciate the depth here — the degenerate |
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.