Fork of github.com/did-method-plc/did-method-plc
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add config for Postgres pool (#57)

* pass cfg to postgres pool

* Update packages/server/service/index.js

Co-authored-by: devin ivy <devinivy@gmail.com>

* Add missing index on (did, createdAt) (#58)

* Add index on (did, createdAt)

* rename

* style

---------

Co-authored-by: devin ivy <devinivy@gmail.com>

authored by

Daniel Holmgren
devin ivy
and committed by
GitHub
32d8a854 47675375

+27 -4
+11 -1
packages/server/service/index.js
··· 18 18 await migrateDb.migrateToLatestOrThrow() 19 19 await migrateDb.close() 20 20 } 21 + const dbPoolSize = parseMaybeInt(process.env.DB_POOL_SIZE) 22 + const dbPoolMaxUses = parseMaybeInt(process.env.DB_POOL_MAX_USES) 23 + const dbPoolIdleTimeoutMs = parseMaybeInt(process.env.PDS_DB_POOL_IDLE_TIMEOUT_MS) 21 24 // Use lower-credentialed user to run the app 22 25 const db = Database.postgres({ 23 26 url: pgUrl(dbCreds), 24 27 schema: dbSchema, 28 + poolSize: dbPoolSize, 29 + poolMaxUses: dbPoolMaxUses, 30 + poolIdleTimeoutMs: dbPoolIdleTimeoutMs, 25 31 }) 26 - const port = parseInt(process.env.PORT) 32 + const port = parseMaybeInt(process.env.PORT) 27 33 const plc = PlcServer.create({ db, port, version }) 28 34 const server = await plc.start() 29 35 server.keepAliveTimeout = 90000 ··· 36 42 const pgUrl = ({ username = "postgres", password = "postgres", host = "localhost", port = "5432", database = "postgres", sslmode }) => { 37 43 const enc = encodeURIComponent 38 44 return `postgresql://${username}:${enc(password)}@${host}:${port}/${database}${sslmode ? `?sslmode=${enc(sslmode)}` : ''}` 45 + } 46 + 47 + const parseMaybeInt = (str) => { 48 + return str ? parseInt(str, 10) : undefined 39 49 } 40 50 41 51 main()
+16 -3
packages/server/src/db/index.ts
··· 26 26 }) 27 27 } 28 28 29 - static postgres(opts: { url: string; schema?: string }): Database { 30 - const { url, schema } = opts 31 - const pool = new PgPool({ connectionString: url }) 29 + static postgres(opts: PgOptions): Database { 30 + const { schema } = opts 31 + const pool = new PgPool({ 32 + connectionString: opts.url, 33 + max: opts.poolSize, 34 + maxUses: opts.poolMaxUses, 35 + idleTimeoutMillis: opts.poolIdleTimeoutMs, 36 + }) 32 37 33 38 // Select count(*) and other pg bigints as js integer 34 39 pgTypes.setTypeParser(pgTypes.builtins.INT8, (n) => parseInt(n, 10)) ··· 230 235 createdAt: row.createdAt.toISOString(), 231 236 })) 232 237 } 238 + } 239 + 240 + export type PgOptions = { 241 + url: string 242 + schema?: string 243 + poolSize?: number 244 + poolMaxUses?: number 245 + poolIdleTimeoutMs?: number 233 246 } 234 247 235 248 export default Database