MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / trimProjects

Method trimProjects

src/mcp/tools.ts:2652–2674  ·  view source on GitHub ↗

* Never evict a graph while a tool call or its timed-out reconcile uses it. * Evicts over the LRU bound, on close, and once idle past the timeout * (#2087). The cache is in last-use order, so idle entries lead it.

(maxOpen = MAX_CACHED_PROJECTS)

Source from the content-addressed store, hash-verified

2650 * (#2087). The cache is in last-use order, so idle entries lead it.
2651 */
2652 private trimProjects(maxOpen = MAX_CACHED_PROJECTS): void {
2653 if (this.activeCalls > 0) return;
2654 const idleMs = resolveProjectIdleTimeoutMs();
2655 const now = Date.now();
2656 for (const [root, cg] of this.projectCache) {
2657 const idle = idleMs > 0 && now - (this.projectUsedAt.get(root) ?? now) >= idleMs;
2658 if (!this.closing && this.projectCache.size <= maxOpen && !idle) break;
2659 if (this.projectGates.has(cg)) continue;
2660 this.projectCache.delete(root);
2661 this.projectUsedAt.delete(root);
2662 if (this.projectLifecycle) {
2663 this.pendingCloses++;
2664 void Promise.resolve(this.projectLifecycle.release(cg)).finally(() => {
2665 this.pendingCloses--;
2666 this.trimProjects();
2667 });
2668 } else cg.close();
2669 }
2670 if (this.closing && this.projectCache.size === 0 && this.pendingCloses === 0) {
2671 for (const resolve of this.closeWaiters.splice(0)) resolve();
2672 }
2673 this.scheduleIdleRelease(idleMs);
2674 }
2675
2676 /**
2677 * Arm one unref'd timer for the oldest project a trim could release. A

Callers 6

openProjectRootMethod · 0.95
awaitProjectGateMethod · 0.95
scheduleIdleReleaseMethod · 0.95
releaseIdleMemoryMethod · 0.95
closeAllMethod · 0.95
executeMethod · 0.95

Calls 9

scheduleIdleReleaseMethod · 0.95
hasMethod · 0.80
getMethod · 0.65
deleteMethod · 0.65
resolveMethod · 0.65
releaseMethod · 0.65
closeMethod · 0.65
resolveFunction · 0.50

Tested by

no test coverage detected