@devries-cameron20 / t3code Mirror · read-only / commits / b5be2ff8da
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

perf(server): read issue tracker bindings once per listing (#39169)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Adamulek123 committed Nov 19, 2026 at 17:24 UTC b5be2ff8da650cc91a0e38850c6bc4afeccab746
2 files changed +89 -58
apps/server/src/issue/IssueService.test.ts
+46 -15
@@ -156,7 +156,7 @@ function makeService(input: {
156 readonly projects: ReadonlyArray<OrchestrationProjectShell>;
157 readonly trackers: ReadonlyArray<IssueTrackerApi>;
158 readonly bindings?: Record<string, IssueTrackerProjectBinding>;
159 - readonly bindingsFailure?: PersistenceSqlError;
159 + readonly readBindings?: IssueTrackerBindings.IssueTrackerBindingsRepository["Service"]["list"];
160 }) {
161 return IssueService.IssueService.pipe(
162 Effect.provide(
@@ -165,16 +165,15 @@ function makeService(input: {
165 Layer.mergeAll(
166 Layer.mock(IssueTrackerBindings.IssueTrackerBindingsRepository)({
167 list:
168 - input.bindingsFailure !== undefined
169 - ? Effect.fail(input.bindingsFailure)
170 - : Effect.succeed(
171 - new Map(
172 - Object.entries(input.bindings ?? {}).map(([id, binding]) => [
173 - id as ProjectId,
174 - binding,
175 - ]),
176 - ),
177 - ),
168 + input.readBindings ??
169 + Effect.succeed(
170 + new Map(
171 + Object.entries(input.bindings ?? {}).map(([id, binding]) => [
172 + id as ProjectId,
173 + binding,
174 + ]),
175 + ),
176 + ),
177 }),
178 Layer.succeed(
179 IssueTrackerRegistry.IssueTrackerRegistry,
@@ -510,6 +509,36 @@ describe("IssueService", () => {
509 });
510
511 describe("IssueService with a standalone tracker", () => {
512 + it.effect("reads bindings once per listing and sees changes on the next listing", () =>
513 + Effect.gen(function* () {
514 + const web = project({ id: "web", repository: "acme/web" });
515 + const docs = project({ id: "docs", repository: "acme/docs" });
516 + let reads = 0;
517 + let scope = "ENG";
518 + const service = yield* makeService({
519 + projects: [web, docs],
520 + trackers: [fakeTracker(), fakeStandaloneTracker()],
521 + readBindings: Effect.sync(() => {
522 + reads += 1;
523 + return new Map([[web.id, { tracker: LINEAR, scope }]]);
524 + }),
525 + });
526 +
527 + const first = yield* service.list({ state: "open" });
528 + expect(first.scopes?.map((entry) => entry.scope)).toEqual(["ENG", "acme/web", "acme/docs"]);
529 + expect(reads).toBe(1);
530 +
531 + scope = "OPS";
532 + const next = yield* service.list({ state: "open", refresh: true });
533 + expect(next.scopes?.map((entry) => entry.scope)).toEqual(["OPS", "acme/web", "acme/docs"]);
534 + expect(reads).toBe(2);
535 +
536 + const missing = yield* service.list({ state: "open", projectId: "missing" as ProjectId });
537 + expect(missing.scopes).toEqual([]);
538 + expect(reads).toBe(2);
539 + }),
540 + );
541 +
542 it.effect("rejects a URL from another workspace with the same team and issue key", () =>
543 Effect.gen(function* () {
544 const service = yield* makeService({
@@ -643,10 +672,12 @@ describe("IssueService with a standalone tracker", () => {
672 const unreadable = yield* makeService({
673 projects,
674 trackers,
646 - bindingsFailure: new PersistenceSqlError({
647 - operation: "IssueTrackerBindingsRepository.list",
648 - detail: "disk I/O error",
649 - }),
675 + readBindings: Effect.fail(
676 + new PersistenceSqlError({
677 + operation: "IssueTrackerBindingsRepository.list",
678 + detail: "disk I/O error",
679 + }),
680 + ),
681 });
682 expect(yield* Effect.flip(unreadable.list({ state: "open" }))).toMatchObject({
683 _tag: "IssueOperationError",
apps/server/src/issue/IssueService.ts
+43 -43
@@ -28,6 +28,7 @@ import {
28 type IssueSetStateInput,
29 type IssueTemplateList,
30 type IssueTrackerSummary,
31 + type IssueTrackerProjectBinding,
32 type IssueUpdateInput,
33 type OrchestrationProjectShell,
34 type ProjectId,
@@ -189,31 +190,12 @@ const make = Effect.gen(function* () {
190 const repositoryIdentities = yield* RepositoryIdentityResolver.RepositoryIdentityResolver;
191 const bindings = yield* IssueTrackerBindings.IssueTrackerBindingsRepository;
192
192 - // Read per resolution so a binding saved in Settings applies without a restart.
193 - const resolveStandaloneBinding = (
194 - project: OrchestrationProjectShell,
195 - ): Effect.Effect<ProjectTrackerBinding | null, IssueOperationError> =>
196 - bindings.list.pipe(
197 - Effect.map((bound) => {
198 - const binding = bound.get(project.id);
199 - const api = binding === undefined ? null : registry.get(binding.tracker);
200 - if (binding === undefined || api === null || !isStandaloneIssueTracker(api)) return null;
201 - return {
202 - tracker: binding.tracker,
203 - host: api.standalone.host,
204 - scope: binding.scope,
205 - };
206 - }),
207 - // A failed read is not an unbound project: that would list the git host's issues alone.
208 - Effect.mapError(
209 - (cause) =>
210 - new IssueOperationError({
211 - operation: "listProjects",
212 - detail: "The project's issue tracker binding could not be read.",
213 - cause,
214 - }),
215 - ),
216 - );
193 + const resolveStandaloneBinding = (binding: IssueTrackerProjectBinding | undefined) => {
194 + if (binding === undefined) return null;
195 + const api = registry.get(binding.tracker);
196 + if (api === null || !isStandaloneIssueTracker(api)) return null;
197 + return { tracker: binding.tracker, host: api.standalone.host, scope: binding.scope };
198 + };
199
200 /**
201 * 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* () {
203 */
204 const resolveProjectTracker = (
205 project: OrchestrationProjectShell,
224 - ): Effect.Effect<ReadonlyArray<ProjectTrackerBinding>, IssueOperationError> =>
225 - Effect.all([
226 - resolveStandaloneBinding(project),
227 - (project.repositoryIdentity != null
228 - ? Effect.succeed(project.repositoryIdentity)
229 - : repositoryIdentities.resolve(project.workspaceRoot)
230 - ).pipe(
231 - Effect.map((repositoryIdentity) =>
206 + binding: IssueTrackerProjectBinding | undefined,
207 + ) =>
208 + (project.repositoryIdentity != null
209 + ? Effect.succeed(project.repositoryIdentity)
210 + : repositoryIdentities.resolve(project.workspaceRoot)
211 + ).pipe(
212 + Effect.map((repositoryIdentity) =>
213 + [
214 + resolveStandaloneBinding(binding),
215 resolveGitHostBinding({ ...project, repositoryIdentity }),
233 - ),
216 + ].filter((candidate) => candidate !== null),
217 ),
235 - ]).pipe(Effect.map((resolved) => resolved.filter((binding) => binding !== null)));
218 + );
219
220 const listProjects = (filter: {
221 readonly projectId?: IssueListInput["projectId"];
@@ -252,15 +235,32 @@ const make = Effect.gen(function* () {
235 cause,
236 }),
237 ),
255 - Effect.flatMap((shells) =>
256 - Effect.forEach(
257 - shells,
258 - (project) =>
259 - resolveProjectTracker(project).pipe(
260 - Effect.map((bindings) => bindings.map((binding) => ({ project, ...binding }))),
238 + Effect.flatMap(
239 + Effect.fnUntraced(function* (shells) {
240 + if (shells.length === 0) return [];
241 + // One read per listing, not per project, and never cached so Settings changes apply.
242 + const bound = yield* bindings.list.pipe(
243 + // A failed read is not an unbound project: that would list the git host's issues alone.
244 + Effect.mapError(
245 + (cause) =>
246 + new IssueOperationError({
247 + operation: "listProjects",
248 + detail: "The project's issue tracker binding could not be read.",
249 + cause,
250 + }),
251 ),
262 - { concurrency: SCOPE_CONCURRENCY },
263 - ),
252 + );
253 + return yield* Effect.forEach(
254 + shells,
255 + (project) =>
256 + resolveProjectTracker(project, bound.get(project.id)).pipe(
257 + Effect.map((candidates) =>
258 + candidates.map((candidate) => ({ project, ...candidate })),
259 + ),
260 + ),
261 + { concurrency: SCOPE_CONCURRENCY },
262 + );
263 + }),
264 ),
265 Effect.map((bound) => {
266 const host = filter.host?.trim().toLowerCase();