-
Notifications
You must be signed in to change notification settings - Fork 4
feat(ui): persistent timeline cache with stale-while-revalidate #427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
67882bf
53c77c4
b8234b7
3591777
91a8bb4
b75ead2
4bd2a0f
a1d7ae2
5a6f5ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,6 +90,7 @@ | |
|
|
||
| let timeline = $state<BranchTimelineData | null>(null); | ||
| let loading = $state(true); | ||
| let revalidating = $state(false); | ||
| let error = $state<string | null>(null); | ||
| let showBranchDiff = $state(false); | ||
| let loadedTimelineKey = $state<string | null>(null); | ||
|
|
@@ -283,12 +284,45 @@ | |
| void loadTimeline(); | ||
| }); | ||
|
|
||
| let revalidationVersion = 0; | ||
|
|
||
| async function loadTimeline() { | ||
| const isInitialLoad = !timeline; | ||
| error = null; | ||
| // Cancel any in-flight revalidation so it can't overwrite fresher data | ||
| revalidationVersion++; | ||
|
|
||
| if (isInitialLoad) { | ||
| const { cached, fresh } = commands.getBranchTimelineWithRevalidation(branch.id); | ||
| if (cached) { | ||
| // Show stale data immediately | ||
| timeline = cached; | ||
| loading = false; | ||
| prunedSessionIds = sessionMgr.prunePendingSessionItems(cached); | ||
| revalidating = true; | ||
| const version = revalidationVersion; | ||
| fresh | ||
| .then((next) => { | ||
| if (version !== revalidationVersion) return; | ||
| error = null; | ||
| timeline = next; | ||
| prunedSessionIds = sessionMgr.prunePendingSessionItems(next); | ||
| void loadTimelineReviewDetails(next.reviews); | ||
| }) | ||
| .catch((e) => { | ||
| if (version !== revalidationVersion) return; | ||
| error = e instanceof Error ? e.message : String(e); | ||
|
Comment on lines
+309
to
+311
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In the stale-while-revalidate path, a transient failure now assigns Useful? React with 👍 / 👎. |
||
| }) | ||
| .finally(() => { | ||
| if (version !== revalidationVersion) return; | ||
| revalidating = false; | ||
| }); | ||
| return; | ||
| } | ||
| // No cache — show loading spinner as before | ||
| loading = true; | ||
| } | ||
| error = null; | ||
|
|
||
| try { | ||
| const nextTimeline = await commands.getBranchTimeline(branch.id, { force: !isInitialLoad }); | ||
| timeline = nextTimeline; | ||
|
|
@@ -715,7 +749,7 @@ | |
| <Spinner size={14} /> | ||
| <span>Loading...</span> | ||
| </div> | ||
| {:else if error} | ||
| {:else if error && !timeline} | ||
| <div class="error"> | ||
| <span>{error}</span> | ||
| </div> | ||
|
|
@@ -726,6 +760,7 @@ | |
| pendingDropNotes={isLocal ? pendingDropNotes : undefined} | ||
| pendingItems={sessionMgr.pendingSessionItems} | ||
| {prunedSessionIds} | ||
| {revalidating} | ||
| deletingItems={timelineDeletingItems} | ||
| reviewCommentBreakdown={timelineReviewDetailsById} | ||
| onSessionClick={(sid) => sessionMgr.handleTimelineSessionClick(sid)} | ||
|
|
@@ -772,6 +807,11 @@ | |
| {/if} | ||
| {/snippet} | ||
| </BranchTimeline> | ||
| {#if error} | ||
| <div class="error revalidation-error"> | ||
| <span>{error}</span> | ||
| </div> | ||
| {/if} | ||
| {/if} | ||
| </div> | ||
| {/if} | ||
|
|
@@ -1026,6 +1066,11 @@ | |
| font-size: var(--size-sm); | ||
| } | ||
|
|
||
| .revalidation-error { | ||
| padding: 4px 12px; | ||
| color: var(--text-faint); | ||
| } | ||
|
|
||
| /* Worktree error state */ | ||
| .worktree-error { | ||
| display: flex; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getBranchTimelineWithRevalidation()starts a forced fetch immediately, andgetBranchTimeline()still deduplicates by branch ID against any in-flight request. That means if the user starts a note/commit while this initial refresh is still running, the laterloadTimeline()calls that are meant to show the new pending stub immediately (see thesession-status-changedhandler inBranchCard.svelte) collapse onto the older request that was issued before the new session existed. On slower timelines, the card can therefore stay stuck on the pre-action state until some later refresh happens.Useful? React with 👍 / 👎.