perf: scope-helper + caching#63
Open
CompN3rd wants to merge 3 commits into
Open
Conversation
Extract reusable TtlCache<T> class to src/utils/ttlCache.ts. Add 5-minute TTL cache to AdoClient.getWorkItemTypes to avoid redundant API calls when querying work item types for the same project within the cache window. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Create forEachScope<T>() in async.ts that combines resolveProjectScopes + mapWithConcurrencyLimit into a single reusable pattern returning { scopes, items }.
Migrate workItemProvider, pipelinesProvider, pullRequestProvider, and planningProviders to use the helper, removing the duplicate resolveProjectScopes + mapParallelLimit boilerplate and the MAX_CONCURRENT_SCOPE_REQUESTS constants from each file.
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)
Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
There was a problem hiding this comment.
Pull request overview
This PR introduces reusable helpers to reduce redundant Azure DevOps API calls and remove repeated multi-scope concurrency boilerplate across several tree providers.
Changes:
- Added a generic
TtlCache<T>utility and used it to cacheAdoClient.getWorkItemTypes()for 5 minutes. - Introduced
forEachScope()to combineresolveProjectScopes()+mapWithConcurrencyLimit()into a single helper returning{ scopes, items }. - Migrated Work Items, Pull Requests, Pipelines, and Planning providers to use
forEachScope()and removed their per-file concurrency constants/loader helpers.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils/ttlCache.ts | Adds a small TTL cache primitive used for API result caching. |
| src/utils/async.ts | Adds forEachScope() helper alongside existing concurrency mapper. |
| src/providers/workItemProvider.ts | Replaces per-scope loader boilerplate with forEachScope(). |
| src/providers/pullRequestProvider.ts | Uses forEachScope() for bucket PR loading and removes redundant helper. |
| src/providers/planningProviders.ts | Uses forEachScope() in planning item loading path. |
| src/providers/pipelinesProvider.ts | Uses forEachScope() for pipeline run listing and removes redundant helper. |
| src/api/adoClient.ts | Adds a 5-minute TTL cache for getWorkItemTypes() and clears it on token changes/disconnect. |
|
|
||
| has(key: string): boolean { | ||
| const entry = this._map.get(key); | ||
| return entry !== undefined && entry.expiresAt > Date.now(); |
Comment on lines
+1
to
+16
| import type { AdoClient } from '../api/adoClient'; | ||
| import type { ConfigManager } from '../config/configManager'; | ||
| import { resolveProjectScopes, type ProjectScope } from '../providers/projectScopes'; | ||
|
|
||
| export async function forEachScope<T>( | ||
| client: AdoClient, | ||
| config: ConfigManager, | ||
| fetcher: (scope: ProjectScope) => Promise<T[]>, | ||
| concurrency = 4 | ||
| ): Promise<{ scopes: ProjectScope[]; items: T[] }> { | ||
| const scopes = await resolveProjectScopes(client, config); | ||
| if (scopes.length === 0) { | ||
| return { scopes, items: [] }; | ||
| } | ||
| const nested = await mapWithConcurrencyLimit(scopes, concurrency, fetcher); | ||
| return { scopes, items: nested.flat() }; |
- TtlCache.has() now evicts expired entries (delegates to get()) - Move forEachScope from utils/async.ts to providers/projectScopes.ts so unrelated utils/async consumers don't transitively pull in the provider layer - Capture activeWorkItemQuery.filter / pipelineRunsTop / pipelineRunsFilter before the concurrent fetcher to guard against config changes mid-load
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
TtlCache utility (new)
forEachScope helper (new)
esolveProjectScopes\ + \mapWithConcurrencyLimit\ into one pattern
Migrated to forEachScope
Removed
esolveProjectScopes\ + \mapWithConcurrencyLimit\ imports from migrated files
Verification
pm run compile\ — all TypeScript checks pass