GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — perf(server): turn end reads upstream divergence once, not twice (#40… · pingdotgg/t3code@194025e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src
    • git
      • GitManager.ts
      • GitWorkflowService.ts
    • vcs
      • VcsStatusBroadcaster.test.ts
      • VcsStatusBroadcaster.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/git/GitManager.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/git/GitManager.ts
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ export interface GitLocalStatusOptions {
111111

112112
export interface GitRemoteStatusOptions extends GitVcsDriver.GitRemoteStatusOptions {
113113
readonly refreshMissingPullRequest?: boolean;
114+
/** Details the caller just read without fetching; used instead of reading them again. */
115+
readonly statusDetails?: GitVcsDriver.GitRemoteStatusDetails;
114116
}
115117

116118
export type GitBranchPullRequest = NonNullable<VcsStatusResult["pr"]> & {
@@ -1603,9 +1605,11 @@ export const make = Effect.gen(function* () {
16031605
cwd: string,
16041606
options?: GitRemoteStatusOptions,
16051607
) {
1606-
const details = yield* gitCore
1607-
.statusDetailsRemote(cwd, options)
1608-
.pipe(Effect.catchIf(isNotGitRepositoryError, () => Effect.succeed(null)));
1608+
const details =
1609+
options?.statusDetails ??
1610+
(yield* gitCore
1611+
.statusDetailsRemote(cwd, options)
1612+
.pipe(Effect.catchIf(isNotGitRepositoryError, () => Effect.succeed(null))));
16091613
if (details === null || !details.isRepo) {
16101614
return null;
16111615
}
Collapse file

‎apps/server/src/git/GitWorkflowService.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/git/GitWorkflowService.ts
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export class GitWorkflowService extends Context.Service<
5959
readonly refName: string;
6060
readonly aheadCount: number;
6161
readonly behindCount: number;
62+
readonly details: GitVcsDriver.GitRemoteStatusDetails;
6263
} | null,
6364
GitManagerServiceError
6465
>;
@@ -384,6 +385,7 @@ export const make = Effect.gen(function* () {
384385
refName: details.branch,
385386
aheadCount: details.aheadCount,
386387
behindCount: details.behindCount,
388+
details,
387389
}
388390
: null;
389391
}),
Collapse file

‎apps/server/src/vcs/VcsStatusBroadcaster.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/vcs/VcsStatusBroadcaster.test.ts
+46-9Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ function layerTestFor(state: {
7878
localInvalidationCalls: number;
7979
remoteInvalidationCalls: number;
8080
remoteStatusRefreshUpstreamValues?: Array<boolean | undefined>;
81+
remoteStatusReusedDetails?: Array<boolean>;
8182
localStatusBranchChanges?: Array<boolean>;
8283
refSnapshot?: string | null;
8384
remoteStatusError?: GitManagerError;
@@ -144,22 +145,37 @@ function layerTestFor(state: {
144145
readRefSnapshot: () =>
145146
Effect.sync(() => (state.refSnapshot === undefined ? "refs" : state.refSnapshot)),
146147
upstreamDivergence: () =>
147-
Effect.sync(() =>
148-
state.currentRemoteStatus?.hasUpstream && state.currentLocalStatus.refName !== null
149-
? {
150-
refName: state.currentLocalStatus.refName,
151-
aheadCount: (state.currentDivergence ?? state.currentRemoteStatus).aheadCount,
152-
behindCount: (state.currentDivergence ?? state.currentRemoteStatus).behindCount,
153-
}
154-
: null,
155-
),
148+
Effect.sync(() => {
149+
const refName = state.currentLocalStatus.refName;
150+
if (!state.currentRemoteStatus?.hasUpstream || refName === null) return null;
151+
const { aheadCount, behindCount } =
152+
state.currentDivergence ?? state.currentRemoteStatus;
153+
return {
154+
refName,
155+
aheadCount,
156+
behindCount,
157+
details: {
158+
isRepo: true,
159+
hasPrimaryRemote: true,
160+
defaultBranch: "main",
161+
isDefaultBranch: false,
162+
branch: refName,
163+
upstreamRef: `origin/${refName}`,
164+
hasUpstream: true,
165+
aheadCount,
166+
behindCount,
167+
aheadOfDefaultCount: aheadCount,
168+
},
169+
};
170+
}),
156171
remoteStatus: (_input, options) =>
157172
Effect.suspend(() => {
158173
return (state.beforeRemoteStatus ?? Effect.void).pipe(
159174
Effect.andThen(
160175
Effect.sync(() => {
161176
state.remoteStatusCalls += 1;
162177
state.remoteStatusRefreshUpstreamValues?.push(options?.refreshUpstream);
178+
state.remoteStatusReusedDetails?.push(options?.statusDetails !== undefined);
163179
return state.currentRemoteStatus;
164180
}),
165181
),
@@ -794,6 +810,27 @@ describe("VcsStatusBroadcaster", () => {
794810
},
795811
);
796812

813+
it.effect("the turn-end PR lookup reuses the upstream read it follows, once", () => {
814+
const state: Parameters<typeof layerTestFor>[0] = {
815+
currentLocalStatus: baseLocalStatus,
816+
currentRemoteStatus: remoteStatusWithPr,
817+
localStatusCalls: 0,
818+
remoteStatusCalls: 0,
819+
localInvalidationCalls: 0,
820+
remoteInvalidationCalls: 0,
821+
remoteStatusReusedDetails: [],
822+
};
823+
824+
return Effect.gen(function* () {
825+
const broadcaster = yield* VcsStatusBroadcaster.VcsStatusBroadcaster;
826+
yield* broadcaster.getStatus({ cwd: "/repo" });
827+
yield* broadcaster.refreshLocalStatus("/repo");
828+
yield* broadcaster.refreshPullRequestStatus("/repo");
829+
yield* broadcaster.refreshPullRequestStatus("/repo");
830+
assert.deepStrictEqual(state.remoteStatusReusedDetails, [false, true, false]);
831+
}).pipe(Effect.provide(layerTestFor(state)));
832+
});
833+
797834
it.effect.each([0, 2])(
798835
"refreshes merge divergence while a lookup ends with %s commits behind",
799836
(behindAfterLookup) => {
Collapse file

‎apps/server/src/vcs/VcsStatusBroadcaster.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/vcs/VcsStatusBroadcaster.ts
+16-1Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import * as BackgroundPolicy from "../background/BackgroundPolicy.ts";
3737
import * as GitWorkflowService from "../git/GitWorkflowService.ts";
3838
import * as ProjectStore from "../orchestration-v2/ProjectStore.ts";
3939
import * as ServerSettings from "../serverSettings.ts";
40+
import type * as GitVcsDriver from "./GitVcsDriver.ts";
4041
import { VcsAutomaticFetchInterval } from "./VcsAutomaticFetchInterval.ts";
4142

4243
const VCS_STATUS_REFRESH_FAILURE_BASE_DELAY = Duration.seconds(30);
@@ -330,6 +331,9 @@ export const make = Effect.gen(function* () {
330331
// A refresh that started after a request saw every change that request could mean, so queued
331332
// callers share it instead of each running git status again.
332333
const localRefreshRequests = new Map<string, number>();
334+
// Upstream details the turn-end refreshLocalStatus just read, handed once to the PR lookup that
335+
// follows it so the same no-fetch read is not repeated. Any remote write in between drops them.
336+
const upstreamReads = new Map<string, GitVcsDriver.GitRemoteStatusDetails>();
333337
const localRefreshResults = new Map<
334338
string,
335339
{
@@ -353,6 +357,7 @@ export const make = Effect.gen(function* () {
353357
// A queued caller can read git again. Keep the monotonic request counter so it cannot
354358
// mistake an older result for a later request.
355359
localRefreshResults.delete(candidate);
360+
upstreamReads.delete(candidate);
356361
}
357362
return cache;
358363
};
@@ -449,6 +454,7 @@ export const make = Effect.gen(function* () {
449454

450455
const updateCachedRemoteStatus = Effect.fn("VcsStatusBroadcaster.updateCachedRemoteStatus")(
451456
function* (cwd: string, remote: CachedRemoteStatus | null, options?: { publish?: boolean }) {
457+
upstreamReads.delete(cwd);
452458
const [changed, value] = yield* Ref.modify(cacheRef, (cache) => {
453459
const previous = cache.get(cwd) ?? { local: null, remote: null };
454460
const next = remote?.branch === previous.local?.value.refName ? remote : null;
@@ -556,6 +562,7 @@ export const make = Effect.gen(function* () {
556562
"VcsStatusBroadcaster.refreshLocalStatus",
557563
)(function* (rawCwd) {
558564
const cwd = yield* withFileSystem(normalizeCwd(rawCwd));
565+
upstreamReads.delete(cwd);
559566
const local = yield* refreshLocalStatusCore(cwd);
560567
const cached = yield* getCachedStatus(cwd);
561568
// Divergence is local Git data; a slow forge lookup must not delay turn-end updates.
@@ -577,6 +584,7 @@ export const make = Effect.gen(function* () {
577584
},
578585
{ publish: true },
579586
);
587+
upstreamReads.set(cwd, divergence.details);
580588
}
581589
}
582590
return local;
@@ -590,7 +598,11 @@ export const make = Effect.gen(function* () {
590598
// GitManager's remote TTL cache is keyed by cwd, not the checked-out branch.
591599
yield* workflow.invalidateRemoteStatus(cwd);
592600
const previousRemote = (yield* getCachedStatus(cwd))?.remote;
593-
const remote = yield* workflow.remoteStatus({ cwd }, options);
601+
const { statusDetails, ...remoteOptions } = options ?? {};
602+
const remote = yield* workflow.remoteStatus(
603+
{ cwd },
604+
statusDetails?.branch === branch ? { ...remoteOptions, statusDetails } : remoteOptions,
605+
);
594606
const latest = yield* getCachedStatus(cwd);
595607
// An overlapping turn refresh and fetch can both move divergence during the forge lookup.
596608
const refreshed =
@@ -783,9 +795,12 @@ export const make = Effect.gen(function* () {
783795
const cached = yield* getCachedStatus(cwd);
784796
if (!cached || cached.remote?.value === null) return null;
785797
// Turn completion must update divergence even when background polling is paused.
798+
const statusDetails = upstreamReads.get(cwd);
799+
upstreamReads.delete(cwd);
786800
const remoteRead = yield* readRemoteStatus(cwd, {
787801
refreshUpstream: false,
788802
refreshMissingPullRequest: true,
803+
...(statusDetails ? { statusDetails } : {}),
789804
});
790805
return yield* updateCachedRemoteStatus(cwd, remoteRead, { publish: true });
791806
}),

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.