Skip to content

Skip the origin cache for queries without a template - #1277

Open
illia-haidar wants to merge 2 commits into
porsager:masterfrom
illia-haidar:fix-origin-stack-cache-untagged
Open

illia-haidar wants to merge 2 commits into
porsager:masterfrom
illia-haidar:fix-origin-stack-cache-untagged

Conversation

@illia-haidar

Copy link
Copy Markdown

Fixes #1276

For a query without a template (sql.unsafe(), sql.file(), internal queries), the origin getter falls through to originStackCache.set(this.strings, this[originError].stack). There this[originError] is false and this.strings is a new array per query, so every failure (queryError() reads origin) adds an entry that is never used again. This returns '' early for such queries.

  • The return value is unchanged. The getter already returned '' for them; only the cache entry goes away.
  • Tagged queries and debug: true keep their current branches.
  • A failing unsafe() still reports its SQLSTATE, query and stack.

The new test, Failing queries without a template add nothing to the origin cache, runs a failing sql.unsafe() three times. It counts Map.prototype.set calls keyed by that query's strings array, without measuring memory.

  • It fails without the change (0 != 3).

Locally, against PostgreSQL 17:

  • tests/index.js (ESM) passes on Node 26.0.0 and 24.22.1, all 265 tests;
  • the CJS build passes too;
  • eslint src tests is clean.

This is independent of #1275: it merges with it without conflicts, and the two together pass the suite (266 tests). cjs/, deno/ and cf/ are left for the build step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

originStackCache gains one entry per failing query without a template, without limit

1 participant