remove unnecessary testing, fix columns, feedback

Signed-off-by: lpete@vmware.com <lpete@vmware.com>

fix issues with merge

Signed-off-by: lpete@vmware.com <lpete@vmware.com>
This commit is contained in:
lpete@vmware.com
2023-08-15 10:09:05 -04:00
parent 8f61efaea5
commit a2960b0667
9 changed files with 37 additions and 95 deletions
@@ -25,7 +25,7 @@ exports.up = async function up(knex) {
'A cache of static assets that where previously deployed and may still be lazy-loaded by clients',
);
table
.string('path')
.text('path', 'longtext')
.primary()
.notNullable()
.comment('The path of the file');
@@ -138,20 +138,20 @@ export class StaticAssetsStore implements StaticAssetProvider {
*/
async trimAssets(options: { maxAgeSeconds: number }) {
const { maxAgeSeconds } = options;
let lastModifiedInterval = `now() + interval '${-maxAgeSeconds} seconds'`;
let lastModifiedInterval = this.#db.raw(
`now() + interval '${-maxAgeSeconds} seconds'`,
);
if (this.#db.client.config.client.includes('mysql')) {
lastModifiedInterval = `date_sub(now(), interval ${maxAgeSeconds} second)`;
lastModifiedInterval = this.#db.raw(
`date_sub(now(), interval ${maxAgeSeconds} second)`,
);
} else if (this.#db.client.config.client.includes('sqlite3')) {
lastModifiedInterval = `datetime('now', ?)`;
lastModifiedInterval = this.#db.raw(`datetime('now', ?)`, [
`-${maxAgeSeconds} seconds`,
]);
}
await this.#db<StaticAssetRow>('static_assets_cache')
.where(
'last_modified_at',
'<=',
this.#db.client.config.client.includes('sqlite3')
? this.#db.raw(lastModifiedInterval, [`-${maxAgeSeconds} seconds`])
: this.#db.raw(lastModifiedInterval),
)
.where('last_modified_at', '<=', lastModifiedInterval)
.delete();
}
}