GeezerVison is showing github.com — fix(azure-devops): issue lists reuse each project's states and surviv… · HNRow/r3code@1c41c5e
File treeExpand file treeCollapse file tree Open diff view settings apps/web/src/components/issue packages/source-control-azure-devops/src/server
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/issue/IssuesPage.tsx +7-1Lines changed: 7 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -216,7 +216,13 @@ export function IssuesPage() { | 216 | 216 | input: listInput, | 217 | 217 | })); | 218 | 218 | const list = useIssueList(targets); | 219 | | - useLiveRefresh(list.refresh, { key: JSON.stringify(targets) }); | | 219 | + // Refreshing a list still loading would cancel it and start over, losing the scopes already read. | | 220 | + useLiveRefresh( | | 221 | + () => { | | 222 | + if (!list.isPending) list.refresh(); | | 223 | + }, | | 224 | + { key: JSON.stringify(targets) }, | | 225 | + ); | 220 | 226 |
| 221 | 227 | const [pages, setPages] = useState<ReadonlyMap<EnvironmentId, HeldIssuePage>>(new Map()); | 222 | 228 | const held = holdIssuePages(list.answers, pages); | |
Collapse file Copy file name to clipboardExpand all lines: packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.test.ts +10-3Lines changed: 10 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -219,6 +219,7 @@ describe("AzureDevOpsIssueTracker", () => { | 219 | 219 | const fs = yield* FileSystem.FileSystem; | 220 | 220 | const bodies: string[] = []; | 221 | 221 | const hydrated: string[] = []; | | 222 | + let typeReads = 0; | 222 | 223 | const api = yield* AzureDevOpsIssueTracker.make.pipe( | 223 | 224 | Effect.provide( | 224 | 225 | Layer.mock(AzureDevOpsCli.AzureDevOpsCli)({ | @@ -238,6 +239,7 @@ describe("AzureDevOpsIssueTracker", () => { | 238 | 239 | ); | 239 | 240 | } | 240 | 241 | if (resource !== "wiql" && resource !== "workitemsbatch") { | | 242 | + if (resource === "workitemtypes") typeReads += 1; | 241 | 243 | return Effect.succeed(TestSourceControlHost.processOutput(answer(args))); | 242 | 244 | } | 243 | 245 | return fs.readFileString(args[args.indexOf("--in-file") + 1]!).pipe( | @@ -260,7 +262,7 @@ describe("AzureDevOpsIssueTracker", () => { | 260 | 262 | }), | 261 | 263 | ), | 262 | 264 | ); | 263 | | - const page = yield* api.listIssues({ | | 265 | + const list = api.listIssues({ | 264 | 266 | cwd: "/w", | 265 | 267 | host: "dev.azure.com", | 266 | 268 | scope: "acme/Web App", | @@ -273,11 +275,16 @@ describe("AzureDevOpsIssueTracker", () => { | 273 | 275 | limit: 2, | 274 | 276 | cursor: "2026-07-01T00:00:00Z|7", | 275 | 277 | }); | | 278 | + const page = yield* list; | | 279 | + yield* list; | 276 | 280 | // The rows come back in WIQL's order, and the cursor is the last one of the page. | 277 | | - expect(hydrated).toEqual(["9,7"]); | | 281 | + expect(hydrated).toEqual(["9,7", "9,7"]); | 278 | 282 | expect(page.items.map((item) => item.key)).toEqual(["9", "7"]); | 279 | 283 | expect(page.nextCursor).toBe("2026-07-01T00:00:00Z|7"); | 280 | | - expect(bodies).toHaveLength(1); | | 284 | + // Each `az` call costs seconds, so a second list reuses the project's states. | | 285 | + expect(typeReads).toBe(1); | | 286 | + expect(bodies).toHaveLength(2); | | 287 | + expect(bodies[1]).toBe(bodies[0]); | 281 | 288 | expect(bodies[0]).toContain("AND [System.State] NOT IN ('shipped')"); | 282 | 289 | const { query } = JSON.parse(bodies[0]!) as { query: string }; | 283 | 290 | // Mentions cannot be asked for over REST, so the filter sends no clause for them. | |
Collapse file Copy file name to clipboardExpand all lines: packages/source-control-azure-devops/src/server/AzureDevOpsIssueTracker.ts +21-5Lines changed: 21 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | * scope is `organization/project` and every call names the organization. Listing is a WIQL | 4 | 4 | * query paged by a `(changedDate, id)` keyset cursor, because WIQL has no offset. | 5 | 5 | */ | | 6 | +import * as Cache from "effect/Cache"; | | 7 | +import * as Duration from "effect/Duration"; | 6 | 8 | import * as Effect from "effect/Effect"; | | 9 | +import * as Exit from "effect/Exit"; | 7 | 10 | import * as FileSystem from "effect/FileSystem"; | 8 | 11 | import * as Result from "effect/Result"; | 9 | 12 | import * as Schema from "effect/Schema"; | @@ -67,6 +70,7 @@ const VIEWER_PERMISSIONS: IssueViewerPermissions = { | 67 | 70 |
| 68 | 71 | const REST_API_VERSION = "7.1"; | 69 | 72 | const PAGE_SIZE = 100; | | 73 | +const CLOSED_STATES_TTL = Duration.minutes(10); | 70 | 74 | /** Updates are read a page per `az` process, oldest first, so a long history is bounded. */ | 71 | 75 | const UPDATE_PAGE_LIMIT = 5; | 72 | 76 | /** Linked pull requests are read one `az` process each, so a work item's links are bounded. */ | @@ -356,8 +360,19 @@ export const make: Effect.Effect< | 356 | 360 | decode: decodeAs(decodeTypes), | 357 | 361 | }).pipe(Effect.map((types) => types.value)); | 358 | 362 |
| 359 | | - const closedStates = (input: Parameters<typeof workItemTypes>[0]) => | 360 | | - workItemTypes(input).pipe(Effect.map(closedStateNames)); | | 363 | + // Each `az` call costs seconds of startup, and a project's states rarely change. | | 364 | + const listClosedStates = yield* Cache.makeWith( | | 365 | + (key: string) => { | | 366 | + const [cwd, organization, project] = JSON.parse(key) as [string, string, string]; | | 367 | + return workItemTypes({ cwd, organization, project, operation: "listIssues" }).pipe( | | 368 | + Effect.map(closedStateNames), | | 369 | + ); | | 370 | + }, | | 371 | + { | | 372 | + capacity: 256, | | 373 | + timeToLive: (exit) => (Exit.isSuccess(exit) ? CLOSED_STATES_TTL : Duration.zero), | | 374 | + }, | | 375 | + ); | 361 | 376 |
| 362 | 377 | const workItem = (input: { | 363 | 378 | readonly cwd: string; | @@ -599,9 +614,10 @@ export const make: Effect.Effect< | 599 | 614 | const dateField = created ? "[System.CreatedDate]" : "[System.ChangedDate]"; | 600 | 615 | return yield* scoped("listIssues", input).pipe( | 601 | 616 | Effect.flatMap((scope) => | 602 | | - closedStates({ ...scope, cwd: input.cwd, operation: "listIssues" }).pipe( | 603 | | - Effect.map((closed) => ({ scope, closed })), | 604 | | - ), | | 617 | + Cache.get( | | 618 | + listClosedStates, | | 619 | + JSON.stringify([input.cwd, scope.organization, scope.project]), | | 620 | + ).pipe(Effect.map((closed) => ({ scope, closed }))), | 605 | 621 | ), | 606 | 622 | Effect.flatMap(({ scope, closed }) => | 607 | 623 | invokeWithBody({ | |
|