From 66e47432a95667385c86939e38ae194a03fcc00a Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Wed, 11 Nov 2026 16:15:00 -0800 Subject: [PATCH] Use typed statement calls in search resource control Co-authored-by: Jinjing <6427696+AmethystLiang@users.noreply.github.com> --- .../session-search-catalog-batching.test.ts | 50 +++++++++++-------- 1 file changed, 29 insertions(+), 21 deletions(-) diff --git a/src/main/ai-vault-search/session-search-catalog-batching.test.ts b/src/main/ai-vault-search/session-search-catalog-batching.test.ts index df251887454..fceb7f9090a 100644 --- a/src/main/ai-vault-search/session-search-catalog-batching.test.ts +++ b/src/main/ai-vault-search/session-search-catalog-batching.test.ts @@ -64,28 +64,36 @@ it.each([40, 400])( if (!/search_inventory_(sources|entries|activity|epochs|staging)/.test(sql)) { return statement } - return new Proxy(statement, { - get(target, property) { - const method = Reflect.get(target, property) - if (typeof method !== 'function') { - return method - } - return (...args: Parameters) => { - if (['get', 'all', 'iterate', 'run'].includes(String(property))) { - const payload = args.find( - (value) => typeof value === 'string' && value.startsWith('[') - ) - const rows = - sql.includes('json_each(?)') && typeof payload === 'string' - ? JSON.parse(payload).length - : 1 - // Reclaim probes the activity row and three witnesses before its physical update. - localRows += rows * (sql.includes('WITH live AS MATERIALIZED') ? 5 : 1) - } - return Reflect.apply(method, target, args) - } + const count = (args: Parameters) => { + const payload = args.find((value) => typeof value === 'string' && value.startsWith('[')) + const rows = + sql.includes('json_each(?)') && typeof payload === 'string' + ? JSON.parse(payload).length + : 1 + // Reclaim probes the activity row and three witnesses before its physical update. + localRows += rows * (sql.includes('WITH live AS MATERIALIZED') ? 5 : 1) + } + return { + get(...args) { + count(args) + return statement.get(...args) + }, + all(...args) { + count(args) + return statement.all(...args) + }, + iterate(...args) { + count(args) + return statement.iterate(...args) + }, + run(...args) { + count(args) + return statement.run(...args) + }, + setReadBigInts(enabled) { + statement.setReadBigInts(enabled) } - }) + } }) const request = async (command: SessionSearchCatalogCommand) => { envelopes++