Skip to content

feat(task-input): cache cloud repositories so picker renders instantly#2206

Draft
timgl wants to merge 1 commit into
mainfrom
posthog-code/cache-cloud-repos
Draft

feat(task-input): cache cloud repositories so picker renders instantly#2206
timgl wants to merge 1 commit into
mainfrom
posthog-code/cache-cloud-repos

Conversation

@timgl
Copy link
Copy Markdown

@timgl timgl commented May 18, 2026

Summary

Clicking New task next to a repo in the sidebar would show a "Loading repos..." spinner in the GitHub repo picker, even though the answer was almost always the same repo the user picked last time. The picker waited on a full integrations + per-installation repo fetch from PostHog every mount, and only then could it validate the selection against the live list.

This change persists the user repository map in settingsStore and uses it as a stand-in while the live data loads, so the picker renders the last-used repo immediately. The network request still fires in the background and replaces the cache when it returns; the existing cleanup effect will still clear the selection if the repo turns out to be gone.

Changes

  • settingsStore: new persisted field cachedCloudRepositoryMap (repo name → { userIntegrationId, installationId }) + setter.
  • useUserRepositoryIntegration:
    • Writes fresh repo map to cache once everything has loaded.
    • Clears the cache when the user has no integrations.
    • Substitutes the cached map for repositoryMap while live queries are pending and repositoryMap is still empty.
    • Treats hasGithubIntegration as true while integrations are loading if cache is non-empty, so the picker doesn't briefly collapse to local mode on cold start.

No changes to TaskInput are required — the existing selectedCloudRepository validation and the cleanup effect both already work against whatever the hook returns.

Test plan

  • Unit: settingsStore persists and rehydrates cachedCloudRepositoryMap (added tests).
  • Cold start with a cached repo: clicking New task in the sidebar shows the previously selected repo immediately, no "Loading repos..." spinner.
  • First-ever launch (empty cache): behavior is unchanged — shows the loading state until repos load.
  • User removes a GitHub integration that contains the cached repo: after live data loads, the selection clears (existing cleanup effect).
  • User has zero GitHub integrations: cache gets cleared, picker shows "No GitHub repos".
  • Refreshing repos via the picker's refresh button still works; cache gets updated to the fresh data.

Created with PostHog Code

The cloud repo picker waited on a full integrations + per-installation
repo fetch every time TaskInput mounted, even though the last-used repo
was already known. Persist the repository map in settingsStore and use
it as a stand-in while live data loads, so clicking "new task" shows
the previously selected repo immediately and only kicks the network
request in the background.

Generated-By: PostHog Code
Task-Id: 0b2985a5-f92f-40ad-b3b8-2dc44366566a
@timgl timgl requested review from adboio, skoob13 and tatoalo and removed request for skoob13 May 18, 2026 23:40
return;
}
if (reposPending) return;
if (Object.keys(repositoryMap).length === 0) return;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here we can also add

if (reposPending) [..]
if (failedInstallationIds.length > 0) return;
if (Object.kyes(..)) [..]

so we guard against persisting a partial map

Copy link
Copy Markdown
Contributor

@tatoalo tatoalo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved, just one nit regarding an additional guard to the setCachedCloudRepositoryMap path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants