X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=src%2Fdb%2Fpostgres%2Findex.js;h=e7a006c6d73b5cddff92076653ee37f5548943a4;hb=92661d6fa967999e7e12e86a2f4d5ce314a02c9b;hp=3e97336992999adaee4a077c1f7ef9ddc7719a87;hpb=737fbd003d5c4dfea81b667ef906f1c106a60612;p=websub-hub diff --git a/src/db/postgres/index.js b/src/db/postgres/index.js index 3e97336..e7a006c 100644 --- a/src/db/postgres/index.js +++ b/src/db/postgres/index.js @@ -30,7 +30,7 @@ const schemaVersionsSupported = { max: { major: 1, minor: 0, - patch: 3, + patch: 4, }, }; @@ -61,7 +61,7 @@ class DatabasePostgres extends Database { if (event && event.query && event.query.startsWith('NOTIFY')) { return; } - this.logger[queryLogLevel](_fileScope('pgp:query'), '', { ...common.pick(event, ['query', 'params']) }); + this.logger[queryLogLevel](_fileScope('pgp:query'), '', { ...common.pick(event || {}, ['query', 'params']) }); }; } @@ -71,7 +71,7 @@ class DatabasePostgres extends Database { }; // Deophidiate column names in-place, log results - pgpInitOptions.receive = (data, result, event) => { + pgpInitOptions.receive = ({ data, result, ctx: event }) => { const exemplaryRow = data[0]; for (const prop in exemplaryRow) { const camel = Database._camelfy(prop); @@ -88,7 +88,7 @@ class DatabasePostgres extends Database { return; } // Omitting .rows - const resultLog = common.pick(result, ['command', 'rowCount', 'duration']); + const resultLog = common.pick(result || {}, ['command', 'rowCount', 'duration']); this.logger[queryLogLevel](_fileScope('pgp:result'), '', { query: event.query, ...resultLog }); } }; @@ -377,7 +377,7 @@ class DatabasePostgres extends Database { throw new DBErrors.UnexpectedResult('did not upsert authentication'); } } catch (e) { - this.logger.error(_scope, 'failed', { error: e, identifier, scrubbedCredential }) + this.logger.error(_scope, 'failed', { error: e, identifier, scrubbedCredential }); throw e; } } @@ -789,14 +789,17 @@ class DatabasePostgres extends Database { } - async topicGetByUrl(dbCtx, topicUrl) { + async topicGetByUrl(dbCtx, topicUrl, applyDefaults = true) { const _scope = _fileScope('topicGetByUrl'); this.logger.debug(_scope, 'called', { topicUrl }); let topic; try { topic = await dbCtx.oneOrNone(this.statement.topicGetByUrl, { topicUrl }); - return this._topicDefaults(topic); + if (applyDefaults) { + topic = this._topicDefaults(topic); + } + return topic; } catch (e) { this.logger.error(_scope, 'failed', { error: e, topic, topicUrl }); throw e; @@ -862,7 +865,7 @@ class DatabasePostgres extends Database { const events = await dbCtx.manyOrNone(this.statement.topicPublishHistory, { topicIds: [topicId], daysAgo: days }); const history = Array.from({ length: days }, () => 0); - events.forEach(({ daysAgo, contentUpdates }) => history[daysAgo] = contentUpdates); + events.forEach(({ daysAgo, contentUpdates }) => history[daysAgo] = Number(contentUpdates)); return history; } @@ -900,6 +903,8 @@ class DatabasePostgres extends Database { const _scope = _fileScope('topicSetContent'); const topicSetContentData = { contentType: null, + httpETag: null, + httpLastModified: null, ...data, }; const logData = { @@ -916,7 +921,11 @@ class DatabasePostgres extends Database { if (result.rowCount != 1) { throw new DBErrors.UnexpectedResult('did not set topic content'); } - result = await dbCtx.result(this.statement.topicSetContentHistory, { topicId: data.topicId, contentHash: data.contentHash, contentSize: data.content.length }); + result = await dbCtx.result(this.statement.topicSetContentHistory, { + topicId: data.topicId, + contentHash: data.contentHash, + contentSize: data.content.length, + }); if (result.rowCount != 1) { throw new DBErrors.UnexpectedResult('did not set topic content history'); }