Update project files
This commit is contained in:
+22
-7
@@ -111,15 +111,30 @@ export class BridgeServer {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Cached `/ping` payload. `/ping` is a liveness probe that external tools may
|
||||
* hit frequently; the previous implementation did a full brain-corpus walk
|
||||
* plus a config serialize on *every* hit. We now compute that body at most
|
||||
* once per `PING_CACHE_TTL_MS` and reuse it — the response shape (status /
|
||||
* config / brain) is unchanged, ping just stops walking the brain per hit.
|
||||
*/
|
||||
private _pingCache: { body: string; expiresAt: number } | null = null;
|
||||
private static readonly PING_CACHE_TTL_MS = 5000;
|
||||
|
||||
private handlePing(res: http.ServerResponse) {
|
||||
const brainDir = _getBrainDir();
|
||||
const brainCount = fs.existsSync(brainDir) ? findBrainFiles(brainDir).length : 0;
|
||||
const now = Date.now();
|
||||
if (!this._pingCache || this._pingCache.expiresAt <= now) {
|
||||
const brainDir = _getBrainDir();
|
||||
const brainCount = fs.existsSync(brainDir) ? findBrainFiles(brainDir).length : 0;
|
||||
const body = JSON.stringify({
|
||||
status: 'ok',
|
||||
config: getConfig(),
|
||||
brain: { fileCount: brainCount, enabled: this.provider.brainEnabled }
|
||||
});
|
||||
this._pingCache = { body, expiresAt: now + BridgeServer.PING_CACHE_TTL_MS };
|
||||
}
|
||||
res.writeHead(200, { 'Content-Type': 'application/json' });
|
||||
res.end(JSON.stringify({
|
||||
status: 'ok',
|
||||
config: getConfig(),
|
||||
brain: { fileCount: brainCount, enabled: this.provider.brainEnabled }
|
||||
}));
|
||||
res.end(this._pingCache.body);
|
||||
}
|
||||
|
||||
private handlePost(req: http.IncomingMessage, res: http.ServerResponse, processor: (data: any, res: http.ServerResponse) => Promise<void>) {
|
||||
|
||||
Reference in New Issue
Block a user