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

Method trimProjects

src/mcp/tools.ts:2694–2716  ·  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

2692 * (#2087). The cache is in last-use order, so idle entries lead it.
2693 */
2694 private trimProjects(maxOpen = MAX_CACHED_PROJECTS): void {
2695 if (this.activeCalls > 0) return;
2696 const idleMs = resolveProjectIdleTimeoutMs();
2697 const now = Date.now();
2698 for (const [root, cg] of this.projectCache) {
2699 const idle = idleMs > 0 && now - (this.projectUsedAt.get(root) ?? now) >= idleMs;
2700 if (!this.closing && this.projectCache.size <= maxOpen && !idle) break;
2701 if (this.projectGates.has(cg)) continue;
2702 this.projectCache.delete(root);
2703 this.projectUsedAt.delete(root);
2704 if (this.projectLifecycle) {
2705 this.pendingCloses++;
2706 void Promise.resolve(this.projectLifecycle.release(cg)).finally(() => {
2707 this.pendingCloses--;
2708 this.trimProjects();
2709 });
2710 } else cg.close();
2711 }
2712 if (this.closing && this.projectCache.size === 0 && this.pendingCloses === 0) {
2713 for (const resolve of this.closeWaiters.splice(0)) resolve();
2714 }
2715 this.scheduleIdleRelease(idleMs);
2716 }
2717
2718 /**
2719 * 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