ci: expand CI checks and make consumer sync opt-in

- Add Go, npm, Python, and Java validation to CI
- Run Go tests against PostgreSQL
- Record performance fixes in the report
This commit is contained in:
Gabriel20xx committed 2026-10-19 21:14:31 +00:00
1 parent 199a5efaef
commit 22887fef03
100 files changed
+9740 -429

No files matched your search

+30 -3
View File
@@ -32,6 +32,18 @@ export function isTransientConnectionError(error) {
);
}
const READ_ONLY_STATEMENT = /^\s*select\b/i;
const LOCKING_OR_WRITING_READ = /\bfor\s+(update|share|no\s+key\s+update|key\s+share)\b|\binto\b|\b(nextval|setval)\s*\(/i;
/**
* True for a plain SELECT that cannot change data or sequences. Only these
* statements are retried after a transient error by default.
*/
export function isReadOnlyStatement(text) {
const sql = String(text);
return READ_ONLY_STATEMENT.test(sql) && !LOCKING_OR_WRITING_READ.test(sql);
}
/**
* Owns one pg pool and exposes bounded startup, retry, transaction, and
* shutdown behavior. Domain repositories should depend on this abstraction
@@ -39,10 +51,18 @@ export function isTransientConnectionError(error) {
*/
export class Database {
constructor(options = {}) {
const { pool, ...poolOptions } = options;
const { pool, log = console.error, ...poolOptions } = options;
this.pool = pool || new Pool(poolOptions);
this.ownsPool = !pool;
this.ready = false;
this.log = log;
if (typeof this.pool.on === 'function') {
// pg emits 'error' for an idle client that fails, for example after a
// database restart. With no listener the event is thrown and can end the process.
this.pool.on('error', error => {
this.log(`[database] idle pool client error: ${error?.message || error}`);
});
}
}
static fromEnv(env = process.env) {
@@ -77,12 +97,19 @@ export class Database {
}
}
async query(text, values = []) {
/**
* Runs one statement. After a transient connection error the statement is
* retried only when it is read-only, so a write that committed before the
* connection dropped is not applied twice. Pass `{ retry: true }` to opt a
* known-idempotent statement in, or `{ retry: false }` to opt a read out.
*/
async query(text, values = [], options = {}) {
await this.connect();
try {
return await this.pool.query(text, values);
} catch (error) {
if (!isTransientConnectionError(error)) throw error;
const retry = options.retry ?? isReadOnlyStatement(text);
if (!retry || !isTransientConnectionError(error)) throw error;
return this.pool.query(text, values);
}
}