Skip to content

perf(notifications): refresh enriched details when window regains focus - #3118

Merged
afonsojramos merged 2 commits into
mainfrom
perf/refresh-enrichment-on-window-focus
Jul 29, 2026
Merged

perf(notifications): refresh enriched details when window regains focus#3118
afonsojramos merged 2 commits into
mainfrom
perf/refresh-enrichment-on-window-focus

Conversation

@afonsojramos

Copy link
Copy Markdown
Member

Follow-up to #3102, implementing the approach proposed in #3102 (comment).

Problem

The enrichment cache introduced in #3102 is keyed by account:id:updatedAt, and some subject changes (labels, milestones, reactions) never bump a notification's updatedAt. Those details can therefore drift while the app polls in the background, with nothing to invalidate them until the thread next has real activity.

Change

Bust the enrichment cache when the Gitify window regains focus, so:

  • the cache keeps saving API calls while the app polls in the background (where staleness is invisible),
  • the moment the user actually views the inbox, every visible notification is re-enriched and up to date.

Implementation:

  • New refreshEnrichmentCache(throttleMs) clears the cache and reports whether it did, throttled so rapid window open/close cycles cost at most one extra enrichment pass per throttle window (the fetch interval).
  • The singleton side-effects host subscribes to TanStack's focusManager (the same signal that already drives refetchOnWindowFocus) and, when the cache was actually cleared, triggers an explicit refetch(). The explicit refetch matters because the built-in focus refetch is stale-gated (30s staleTime against a 60s default poll), so roughly half of focus events would otherwise not re-enrich until the next poll; when both fire, TanStack dedupes the concurrent fetches.
  • Ordering is guaranteed: the cache clear runs synchronously within the focus dispatch, while any refetch only reads the cache after its own awaits (TanStack's focus handler additionally awaits before refetching). If those internals ever changed, the degradation is one stale interval, never incorrect data.

Tests

  • notifications.test.ts: fake-timer coverage for clear, throttle, and throttle expiry.
  • useNotifications.test.tsx: the side-effects host refreshes on window focus with the configured interval; plain consumers do not.

@afonsojramos
afonsojramos requested a review from setchy as a code owner July 29, 2026 21:02
@github-actions github-actions Bot added the refactor Refactoring of existing feature label Jul 29, 2026
…nt-on-window-focus

# Conflicts:
#	src/renderer/hooks/useNotifications.test.tsx
@sonarqubecloud

Copy link
Copy Markdown

@afonsojramos
afonsojramos merged commit ffc699c into main Jul 29, 2026
16 checks passed
@afonsojramos
afonsojramos deleted the perf/refresh-enrichment-on-window-focus branch July 29, 2026 21:35
@github-actions github-actions Bot added this to the Release 7.x.x milestone Jul 29, 2026
This was referenced Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Refactoring of existing feature

Development

Successfully merging this pull request may close these issues.

1 participant