mirror of
https://github.com/penpot/penpot.git
synced 2026-11-18 16:12:24 +00:00
* ✨ Add pgjdbc prepared statement cache settings Expose pgjdbc's server-side prepared statement cache as three optional backend variables: PENPOT_DATABASE_PREPARE_THRESHOLD, PENPOT_DATABASE_PREPARED_STATEMENT_CACHE_QUERIES and PENPOT_DATABASE_PREPARED_STATEMENT_CACHE_SIZE (bytes, converted to whole MiB for the driver, rounding up). When unset, the driver defaults apply (5 executions, 256 entries, 5 MiB), so the behavior is unchanged. The values reach Hikari as dataSourceProperties strings, because pgjdbc only reads String values; flushCacheOnDdl stays at its default. Closes #13092 AI-assisted-by: inkling-2-small-free * ♻️ Sync the pool options schema with the code The integrant pool options schema validated a ::connect-timeout option that nothing reads, while the keys the code consumes (::connection-timeout, ::idle-timeout, ::max-lifetime) were missing from it. The schema now declares the three, matching the code and the defaults map. The removed key was not referenced anywhere else. Follow-up to #13092. AI-assisted-by: inkling-2-small-free * ♻️ Rename the prepared statement cache threshold setting Keep the three knobs under one name in the configuration: PENPOT_DATABASE_PREPARED_STATEMENT_CACHE_THRESHOLD PENPOT_DATABASE_PREPARED_STATEMENT_CACHE_QUERIES PENPOT_DATABASE_PREPARED_STATEMENT_CACHE_SIZE The old PENPOT_DATABASE_PREPARE_THRESHOLD read as a verb and was the only one of the three that did not name the prepared statement cache. Fix the documentation of the values: 0 in either cache value disables the cache, not only the size, and -1 prepares a statement from its first execution and forces binary transfer, which is what pgjdbc does. Cover the -1 threshold end to end: it already decoded and validated, but nothing proved that it reaches the driver. The tests also pin 0, so a falsy check cannot silently drop it. Closes #13092 AI-assisted-by: deepseek-v4.1-flash * ♻️ Fix the prepared statement cache contracts The threshold schema accepted any integer, but the driver clamps every negative to -1 and turns on binary transfer, so a typo like -10 changed the wire protocol instead of failing at boot. Both schemas now declare {:min -1}: -1 and the non-negatives stay valid. The tests compared our own dataSourceProperties literals with our own literals, which cannot catch the failure the feature fears (a property the driver ignores). They now read the threshold back from a real connection: 5 with no options, 1 and 0 when configured. The size ceiling is covered one byte over a MiB, and queries=0 too. The docs, the app.db comment and the memory described the threshold 0 as disabling the cache. It does not: 0 stops the server-side prepared statements while the driver's cache of parsed queries stays in use, bounded by the other two values. The same texts lost the pg_prepared_statements pointer (the view only lists the session that runs the query) together with the flushCacheOnDdl and PgBouncer sentences, and the section now carries its version marker. Closes #13092 AI-assisted-by: deepseek-v4.1-flash * 💄 Format the prepared statement cache pool test The continuation arguments of the two with-connection calls were aligned under the options map instead of two spaces past the form, which cljfmt rejects. Local verification missed it because `./scripts/ci backend --test` runs the tests only: lint and format are separate tasks, so the pre-push check is the whole `./scripts/ci backend` or an explicit --lint/--fmt. AI-assisted-by: deepseek-v4.1-flash * ♻️ Address the review of the prepared statement cache The pool startup line shows the three values, so the configured cache is visible without reading the environment back; a nil means the driver default. bytes->mib-ceil uses Math/ceilDiv: the same rounding in one expression, and the size schema already rejects negatives. The cache-limit tests count a closed statement in pg_prepared_statements instead of comparing the property literals. A closed statement stays prepared in the server only while the driver's cache holds it, which is what tells an accepted property from an effective one; the positive case keeps the cache enabled with a sub-MiB size. The config test drops the groups that only exercised the decoder and keeps the ones that pin the accepted range. The manual and the memory note that a query parameter of the same name in PENPOT_DATABASE_URI wins over the variable: pgjdbc ignores the Properties value when the URL carries it. AI-assisted-by: deepseek-v4.1-flash AI-assisted-by: claude-opus-5-5