perf(notifications): skip re-enrichment of unchanged notifications - #3102
perf(notifications): skip re-enrichment of unchanged notifications#3102joshfree wants to merge 2 commits into
Conversation
Cache enriched notification subjects keyed by account + id + updatedAt so that notifications whose updatedAt is unchanged are not re-fetched on every poll. Only cache misses are sent to the batched enrichment path, and the cache is pruned each cycle to the currently-present notifications so it stays bounded. Refs gitify-app#3101
|
Thanks Josh. One question - does the notification timestamp get updated when enriched details change? I looked into this 12-18 mths ago and have a faint (could be incorrect) recollection that there was something quirky about how the notification list data returns with respect to enriched details. There was also some interesting notification timestamp behavior as notifications go from your unread inbox, to done/read, to being manually moved back to your inbox - so we'd need to go ensure our cache key handles this, too |
|
Hey @setchy -- thanks so much for taking the time to look at this, and for the thoughtful question — really appreciate it. On the read/done -> back-to-inbox case: I think the current approach handles it, but you know the notification lifecycle far better than I do, so please tell me if I'm missing the quirk you ran into. The cache only stores the enriched subject and applies it back onto the fresh list item, so read/unread/done state and ordering still come straight from the live list. It also prunes to whatever's currently in the list each cycle, so anything that leaves and returns comes back as a miss and gets re-fetched. On One idea, entirely subject to your preference: instead of a fixed timer (which is awkward anyway, since to actually save any calls it has to be longer than the poll interval, and that's user-configurable), we could tie freshness to the manual refresh -- background polling uses the cache, an explicit refresh clears it and re-enriches. But I'm very happy to go whichever way you think fits Gitify best. How would you like me to handle it? |
Fixes part of #3101 (Improvement 1 of 3).
Problem
On every poll,
getAllNotifications→enrichNotifications(
src/renderer/utils/notifications/notifications.ts) re-fetches subjectdetails for every visible notification, with no change detection. For N
visible notifications this issues
ceil(N / 100)GraphQL detail queries everyinterval even when nothing changed.
Change
Cache the enriched subject keyed by account + notification id +
updatedAt. Oneach poll, notifications whose
updatedAtis unchanged reuse the cached subjectand only cache misses are sent to the batched enrichment path. The cached
subject is applied onto the freshly-listed notification so read state and
ordering stay current, and the cache is pruned each cycle to the
currently-present notifications so it stays bounded.
The change lives in the enrichment orchestrator above the adapter, so it is
forge-agnostic and preserves existing behavior for changed notifications.
Tests
Added coverage in
notifications.test.tsfor the skip-when-unchanged andre-fetch-when-
updatedAt-changes cases.