mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-09 04:57:04 +03:00
Only give up on replica for last retry
This commit is contained in:
@@ -103,6 +103,8 @@ export class Postgres implements IDatabase {
|
|||||||
|
|
||||||
let tries = 0;
|
let tries = 0;
|
||||||
let lastPool: Pool = null;
|
let lastPool: Pool = null;
|
||||||
|
const maxTries = () => (lastPool === this.pool
|
||||||
|
? this.config.postgres.maxTries : this.config.postgresReadOnly.maxTries);
|
||||||
do {
|
do {
|
||||||
tries++;
|
tries++;
|
||||||
|
|
||||||
@@ -133,14 +135,13 @@ export class Postgres implements IDatabase {
|
|||||||
if (lastPool === this.pool) {
|
if (lastPool === this.pool) {
|
||||||
// Only applies if it is get or all request
|
// Only applies if it is get or all request
|
||||||
options.forceReplica = true;
|
options.forceReplica = true;
|
||||||
} else if (lastPool === this.poolRead) {
|
} else if (lastPool === this.poolRead && maxTries() - tries <= 1) {
|
||||||
options.useReplica = false;
|
options.useReplica = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.error(`prepare (postgres) try ${tries}: ${err}`);
|
Logger.error(`prepare (postgres) try ${tries}: ${err}`);
|
||||||
}
|
}
|
||||||
} while (this.isReadQuery(type) && tries < (lastPool === this.pool
|
} while (this.isReadQuery(type) && tries < maxTries());
|
||||||
? this.config.postgres.maxTries : this.config.postgresReadOnly.maxTries));
|
|
||||||
|
|
||||||
throw new Error(`prepare (postgres): ${type} ${query} failed after ${tries} tries`);
|
throw new Error(`prepare (postgres): ${type} ${query} failed after ${tries} tries`);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user