From 872d3bdd90d228cb6bb6d5f5fbe69cc9bc858b80 Mon Sep 17 00:00:00 2001 From: Adamulek123 Date: Thu, 19 Nov 2026 16:35:58 +0100 Subject: [PATCH 1/2] perf(server): read issue tracker bindings once per listing --- apps/server/src/issue/IssueService.test.ts | 61 ++++++++++++---- apps/server/src/issue/IssueService.ts | 85 +++++++++++----------- 2 files changed, 88 insertions(+), 58 deletions(-) diff --git a/apps/server/src/issue/IssueService.test.ts b/apps/server/src/issue/IssueService.test.ts index 723228a64f04..e68799eea12e 100644 --- a/apps/server/src/issue/IssueService.test.ts +++ b/apps/server/src/issue/IssueService.test.ts @@ -156,7 +156,7 @@ function makeService(input: { readonly projects: ReadonlyArray; readonly trackers: ReadonlyArray; readonly bindings?: Record; - readonly bindingsFailure?: PersistenceSqlError; + readonly readBindings?: IssueTrackerBindings.IssueTrackerBindingsRepository["Service"]["list"]; }) { return IssueService.IssueService.pipe( Effect.provide( @@ -165,16 +165,15 @@ function makeService(input: { Layer.mergeAll( Layer.mock(IssueTrackerBindings.IssueTrackerBindingsRepository)({ list: - input.bindingsFailure !== undefined - ? Effect.fail(input.bindingsFailure) - : Effect.succeed( - new Map( - Object.entries(input.bindings ?? {}).map(([id, binding]) => [ - id as ProjectId, - binding, - ]), - ), - ), + input.readBindings ?? + Effect.succeed( + new Map( + Object.entries(input.bindings ?? {}).map(([id, binding]) => [ + id as ProjectId, + binding, + ]), + ), + ), }), Layer.succeed( IssueTrackerRegistry.IssueTrackerRegistry, @@ -510,6 +509,36 @@ describe("IssueService", () => { }); describe("IssueService with a standalone tracker", () => { + it.effect("reads bindings once per listing and sees changes on the next listing", () => + Effect.gen(function* () { + const web = project({ id: "web", repository: "acme/web" }); + const docs = project({ id: "docs", repository: "acme/docs" }); + let reads = 0; + let scope = "ENG"; + const service = yield* makeService({ + projects: [web, docs], + trackers: [fakeTracker(), fakeStandaloneTracker()], + readBindings: Effect.sync(() => { + reads += 1; + return new Map([[web.id, { tracker: LINEAR, scope }]]); + }), + }); + + const first = yield* service.list({ state: "open" }); + expect(first.scopes?.map((entry) => entry.scope)).toEqual(["ENG", "acme/web", "acme/docs"]); + expect(reads).toBe(1); + + scope = "OPS"; + const next = yield* service.list({ state: "open", refresh: true }); + expect(next.scopes?.map((entry) => entry.scope)).toEqual(["OPS", "acme/web", "acme/docs"]); + expect(reads).toBe(2); + + const missing = yield* service.list({ state: "open", projectId: "missing" as ProjectId }); + expect(missing.scopes).toEqual([]); + expect(reads).toBe(2); + }), + ); + it.effect("rejects a URL from another workspace with the same team and issue key", () => Effect.gen(function* () { const service = yield* makeService({ @@ -643,10 +672,12 @@ describe("IssueService with a standalone tracker", () => { const unreadable = yield* makeService({ projects, trackers, - bindingsFailure: new PersistenceSqlError({ - operation: "IssueTrackerBindingsRepository.list", - detail: "disk I/O error", - }), + readBindings: Effect.fail( + new PersistenceSqlError({ + operation: "IssueTrackerBindingsRepository.list", + detail: "disk I/O error", + }), + ), }); expect(yield* Effect.flip(unreadable.list({ state: "open" }))).toMatchObject({ _tag: "IssueOperationError", diff --git a/apps/server/src/issue/IssueService.ts b/apps/server/src/issue/IssueService.ts index 239de06ce546..163072a9eead 100644 --- a/apps/server/src/issue/IssueService.ts +++ b/apps/server/src/issue/IssueService.ts @@ -28,6 +28,7 @@ import { type IssueSetStateInput, type IssueTemplateList, type IssueTrackerSummary, + type IssueTrackerProjectBinding, type IssueUpdateInput, type OrchestrationProjectShell, type ProjectId, @@ -189,31 +190,12 @@ const make = Effect.gen(function* () { const repositoryIdentities = yield* RepositoryIdentityResolver.RepositoryIdentityResolver; const bindings = yield* IssueTrackerBindings.IssueTrackerBindingsRepository; - // Read per resolution so a binding saved in Settings applies without a restart. - const resolveStandaloneBinding = ( - project: OrchestrationProjectShell, - ): Effect.Effect => - bindings.list.pipe( - Effect.map((bound) => { - const binding = bound.get(project.id); - const api = binding === undefined ? null : registry.get(binding.tracker); - if (binding === undefined || api === null || !isStandaloneIssueTracker(api)) return null; - return { - tracker: binding.tracker, - host: api.standalone.host, - scope: binding.scope, - }; - }), - // A failed read is not an unbound project: that would list the git host's issues alone. - Effect.mapError( - (cause) => - new IssueOperationError({ - operation: "listProjects", - detail: "The project's issue tracker binding could not be read.", - cause, - }), - ), - ); + const resolveStandaloneBinding = (binding: IssueTrackerProjectBinding | undefined) => { + if (binding === undefined) return null; + const api = registry.get(binding.tracker); + if (api === null || !isStandaloneIssueTracker(api)) return null; + return { tracker: binding.tracker, host: api.standalone.host, scope: binding.scope }; + }; /** * Where a project's issues live: its bound standalone tracker, its git host's, or both. The @@ -221,18 +203,19 @@ const make = Effect.gen(function* () { */ const resolveProjectTracker = ( project: OrchestrationProjectShell, - ): Effect.Effect, IssueOperationError> => - Effect.all([ - resolveStandaloneBinding(project), - (project.repositoryIdentity != null - ? Effect.succeed(project.repositoryIdentity) - : repositoryIdentities.resolve(project.workspaceRoot) - ).pipe( - Effect.map((repositoryIdentity) => + binding: IssueTrackerProjectBinding | undefined, + ) => + (project.repositoryIdentity != null + ? Effect.succeed(project.repositoryIdentity) + : repositoryIdentities.resolve(project.workspaceRoot) + ).pipe( + Effect.map((repositoryIdentity) => + [ + resolveStandaloneBinding(binding), resolveGitHostBinding({ ...project, repositoryIdentity }), - ), + ].filter((candidate) => candidate !== null), ), - ]).pipe(Effect.map((resolved) => resolved.filter((binding) => binding !== null))); + ); const listProjects = (filter: { readonly projectId?: IssueListInput["projectId"]; @@ -252,15 +235,31 @@ const make = Effect.gen(function* () { cause, }), ), - Effect.flatMap((shells) => - Effect.forEach( - shells, - (project) => - resolveProjectTracker(project).pipe( - Effect.map((bindings) => bindings.map((binding) => ({ project, ...binding }))), + Effect.flatMap( + Effect.fnUntraced(function* (shells) { + if (shells.length === 0) return []; + // Use one fresh binding snapshot for the entire listing, including when Settings changes. + const bound = yield* bindings.list.pipe( + Effect.mapError( + (cause) => + new IssueOperationError({ + operation: "listProjects", + detail: "The project's issue tracker binding could not be read.", + cause, + }), ), - { concurrency: SCOPE_CONCURRENCY }, - ), + ); + return yield* Effect.forEach( + shells, + (project) => + resolveProjectTracker(project, bound.get(project.id)).pipe( + Effect.map((candidates) => + candidates.map((candidate) => ({ project, ...candidate })), + ), + ), + { concurrency: SCOPE_CONCURRENCY }, + ); + }), ), Effect.map((bound) => { const host = filter.host?.trim().toLowerCase(); From b651786f36a7641f98205c1a02cd863a12dbd740 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 19 Nov 2026 15:55:40 +0000 Subject: [PATCH 2/2] refactor(server): keep the binding-read failure invariant comment Co-Authored-By: Claude Opus 5.5 --- apps/server/src/issue/IssueService.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/server/src/issue/IssueService.ts b/apps/server/src/issue/IssueService.ts index 163072a9eead..e4ffc8817628 100644 --- a/apps/server/src/issue/IssueService.ts +++ b/apps/server/src/issue/IssueService.ts @@ -238,8 +238,9 @@ const make = Effect.gen(function* () { Effect.flatMap( Effect.fnUntraced(function* (shells) { if (shells.length === 0) return []; - // Use one fresh binding snapshot for the entire listing, including when Settings changes. + // One read per listing, not per project, and never cached so Settings changes apply. const bound = yield* bindings.list.pipe( + // A failed read is not an unbound project: that would list the git host's issues alone. Effect.mapError( (cause) => new IssueOperationError({