diff --git a/api/src/DuckDBPreparedStatementWeakRefCollection.ts b/api/src/DuckDBPreparedStatementWeakRefCollection.ts index 28759bfc..ff5ed50f 100644 --- a/api/src/DuckDBPreparedStatementWeakRefCollection.ts +++ b/api/src/DuckDBPreparedStatementWeakRefCollection.ts @@ -5,8 +5,13 @@ export class DuckDBPreparedStatementWeakRefCollection implements DuckDBPreparedStatementCollection { preparedStatements: WeakRef[] = []; + lastPruneTime: number = 0; public add(prepared: DuckDBPreparedStatement) { - this.prune(); + const now = performance.now(); + if (now - this.lastPruneTime > 1000) { + this.lastPruneTime = now; + this.prune(); + } this.preparedStatements.push(new WeakRef(prepared)); } public destroySync() { diff --git a/api/test/api.test.ts b/api/test/api.test.ts index d0ab4c46..240cb5a9 100644 --- a/api/test/api.test.ts +++ b/api/test/api.test.ts @@ -2153,7 +2153,7 @@ ORDER BY name }); }); - test('should not segfault with concurrent prepared statement creation and execution', async () => { + test('should not segfault with concurrent prepared statement creation and execution', async () => { await withConnection(async (connection) => { // Create test table with some data await connection.run(`