X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=src%2Fdb%2Fsqlite%2Findex.js;h=56afa000cb886f900277e4bf819139b93e926707;hb=bc2e0acf8844af08633c6ed0df15890a00116599;hp=3fae300eec6b1d02a746f32aae1b3d978bf35fda;hpb=d5e7908d3e60ee0cb3149163d4749563cdfafeb3;p=websub-hub diff --git a/src/db/sqlite/index.js b/src/db/sqlite/index.js index 3fae300..56afa00 100644 --- a/src/db/sqlite/index.js +++ b/src/db/sqlite/index.js @@ -20,7 +20,7 @@ const schemaVersionsSupported = { max: { major: 1, minor: 0, - patch: 2, + patch: 4, }, }; @@ -822,6 +822,18 @@ class DatabaseSQLite extends Database { } + topicPublishHistory(dbCtx, topicId, days) { + const _scope = _fileScope('topicPublishHistory'); + this.logger.debug(_scope, 'called', { topicId, days }) + + const events = this.statement.topicPublishHistory.all({ topicId, daysAgo: days }); + const history = Array.from({ length: days }, () => 0); + events.forEach(({ daysAgo, contentUpdates }) => history[daysAgo] = Number(contentUpdates)); + + return history; + } + + topicSet(dbCtx, data) { const _scope = _fileScope('topicSet'); this.logger.debug(_scope, 'called', data); @@ -853,6 +865,8 @@ class DatabaseSQLite extends Database { const _scope = _fileScope('topicSetContent'); const topicSetContentData = { contentType: null, + httpETag: null, + httpLastModified: null, ...data, }; const logData = { @@ -869,6 +883,14 @@ class DatabaseSQLite extends Database { if (result.changes != 1) { throw new DBErrors.UnexpectedResult('did not set topic content'); } + result = this.statement.topicSetContentHistory.run({ + topicId: data.topicId, + contentHash: data.contentHash, + contentSize: data.content.length, + }); + if (result.changes != 1) { + throw new DBErrors.UnexpectedResult('did not set topic content history'); + } return this._engineInfo(result); } catch (e) { this.logger.error(_scope, 'failed', { error: e, ...logData });