Skip to content

Commit

Permalink
Add more config for pds db pool (bluesky-social#867)
Browse files Browse the repository at this point in the history
  • Loading branch information
devinivy authored Apr 22, 2023
1 parent 8bdb00a commit 308adc2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/pds/service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const main = async () => {
url: pgUrl(env.dbCreds),
schema: env.dbSchema,
poolSize: env.dbPoolSize,
poolMaxUses: env.dbPoolMaxUses,
poolIdleTimeoutMs: env.dbPoolIdleTimeoutMs,
})
const s3Blobstore = new S3BlobStore({ bucket: env.s3Bucket })
const repoSigningKey = await Secp256k1Keypair.import(env.repoSigningKey)
Expand Down Expand Up @@ -100,6 +102,8 @@ const getEnv = () => ({
dbMigrateCreds: JSON.parse(process.env.DB_MIGRATE_CREDS_JSON),
dbSchema: process.env.DB_SCHEMA,
dbPoolSize: maybeParseInt(process.env.DB_POOL_SIZE),
dbPoolMaxUses: maybeParseInt(process.env.DB_POOL_MAX_USES),
dbPoolIdleTimeoutMs: maybeParseInt(process.env.DB_POOL_IDLE_TIMEOUT_MS),
smtpHost: process.env.SMTP_HOST,
smtpUsername: process.env.SMTP_USERNAME,
smtpPassword: process.env.SMTP_PASSWORD,
Expand Down
10 changes: 9 additions & 1 deletion packages/pds/src/db/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ export class Database {
static postgres(opts: PgOptions): Database {
const { schema, url } = opts
const pool =
opts.pool ?? new PgPool({ connectionString: url, max: opts.poolSize })
opts.pool ??
new PgPool({
connectionString: url,
max: opts.poolSize,
maxUses: opts.poolMaxUses,
idleTimeoutMillis: opts.poolIdleTimeoutMs,
})

// Select count(*) and other pg bigints as js integer
pgTypes.setTypeParser(pgTypes.builtins.INT8, (n) => parseInt(n, 10))
Expand Down Expand Up @@ -248,6 +254,8 @@ type PgOptions = {
pool?: PgPool
schema?: string
poolSize?: number
poolMaxUses?: number
poolIdleTimeoutMs?: number
}

type ChannelEvents = {
Expand Down

0 comments on commit 308adc2

Please sign in to comment.