diff --git a/docker-compose.db-dev.yml b/docker-compose.db-dev.yml index f14b626d7..4c27b344c 100644 --- a/docker-compose.db-dev.yml +++ b/docker-compose.db-dev.yml @@ -13,3 +13,11 @@ services: - POSTGRES_PASSWORD=joplin - POSTGRES_USER=joplin - POSTGRES_DB=joplin + + # Use this to specify additional Postgres + # config parameters: + # + # command: + # - "postgres" + # - "-c" + # - "log_min_duration_statement=0" diff --git a/packages/server/src/db.ts b/packages/server/src/db.ts index 246a7a004..dec149643 100644 --- a/packages/server/src/db.ts +++ b/packages/server/src/db.ts @@ -94,7 +94,27 @@ export async function waitForConnection(dbConfig: DatabaseConfig): Promise { - return knex(makeKnexConfig(dbConfig)); + const connection = knex(makeKnexConfig(dbConfig)); + + const debugSlowQueries = false; + + if (debugSlowQueries) { + const startTimes: Record = {}; + + const slowQueryDuration = 10; + + connection.on('query', (data) => { + startTimes[data.__knexQueryUid] = Date.now(); + }); + + connection.on('query-response', (_response, data) => { + const duration = Date.now() - startTimes[data.__knexQueryUid]; + if (duration < slowQueryDuration) return; + console.info(`SQL: ${data.sql} (${duration}ms)`); + }); + } + + return connection; } export async function disconnectDb(db: DbConnection) { diff --git a/packages/server/src/utils/routeUtils.ts b/packages/server/src/utils/routeUtils.ts index 14af2c48c..0b9672af9 100644 --- a/packages/server/src/utils/routeUtils.ts +++ b/packages/server/src/utils/routeUtils.ts @@ -186,7 +186,7 @@ export async function execRequest(routes: Routers, ctx: AppContext) { if (!match) throw new ErrorNotFound(); const endPoint = match.route.findEndPoint(ctx.request.method as HttpMethod, match.subPath.schema); - if (ctx.URL && !isValidOrigin(ctx.URL.origin, baseUrl(endPoint.type), endPoint.type)) throw new ErrorNotFound('Invalid origin', 'invalidOrigin'); + if (ctx.URL && !isValidOrigin(ctx.URL.origin, baseUrl(endPoint.type), endPoint.type)) throw new ErrorNotFound(`Invalid origin: ${ctx.URL.origin}`, 'invalidOrigin'); // This is a generic catch-all for all private end points - if we // couldn't get a valid session, we exit now. Individual end points