X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=src%2Fdb%2Fpostgres%2Findex.js;h=e70aeb7b7883e2700dceb7ce7599d069bf8a515c;hb=43898cdd317a127bc45e8b3cb2f160df386760a1;hp=d950d4a8488924ea2999a9c03b03d93f38ab4591;hpb=33897b863a84ff7d248888f83dc100a96cd9bc49;p=websub-hub diff --git a/src/db/postgres/index.js b/src/db/postgres/index.js index d950d4a..e70aeb7 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, }, }; @@ -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; @@ -856,6 +859,18 @@ class DatabasePostgres extends Database { } + async topicPublishHistory(dbCtx, topicId, days) { + const _scope = _fileScope('topicPublishHistory'); + this.logger.debug(_scope, 'called', { topicId, days }); + + 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] = Number(contentUpdates)); + + return history; + } + + async topicSet(dbCtx, data) { const _scope = _fileScope('topicSet'); this.logger.debug(_scope, 'called', data); @@ -888,6 +903,8 @@ class DatabasePostgres extends Database { const _scope = _fileScope('topicSetContent'); const topicSetContentData = { contentType: null, + httpETag: null, + httpLastModified: null, ...data, }; const logData = { @@ -904,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'); }