fix linting and prettier issues

Signed-off-by: lpete@vmware.com <lpete@vmware.com>
This commit is contained in:
lpete@vmware.com
2023-08-07 13:56:31 -04:00
parent 7143e55652
commit 02cedae992
4 changed files with 33 additions and 27 deletions
+12 -13
View File
@@ -1,26 +1,25 @@
name: "!Test Databases"
name: '!Test Databases'
on:
workflow_dispatch:
pull_request:
branches: [ "mysql" ]
branches: ['mysql']
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: yarn
- run: yarn install
- run: yarn tsc
- run: yarn build:all
- run: yarn test
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: yarn
- run: yarn install
- run: yarn tsc
- run: yarn build:all
- run: yarn test
@@ -24,7 +24,11 @@ exports.up = async function up(knex) {
table.comment(
'A cache of static assets that where previously deployed and may still be lazy-loaded by clients',
);
table.string('path').primary().notNullable().comment('The path of the file');
table
.string('path')
.primary()
.notNullable()
.comment('The path of the file');
table
.dateTime('last_modified_at')
.defaultTo(knex.fn.now())
@@ -153,18 +153,18 @@ describe('StaticAssetsStore', () => {
content: async () => Buffer.alloc(0),
},
]);
// interval check for postgresql
let hourPast = `now() + interval '-3600 seconds'`;
if (knex.client.config.client.includes('mysql')) {
hourPast = `date_sub(now(), interval 3600 second)`;
} else if (knex.client.config.client.includes('sqlite3')) {
hourPast = `datetime('now', '-3600 seconds')`;
}
// Rewrite modified time of "old" to be 1h in the past
const updated = await knex('static_assets_cache')
.where({ path: 'old' })
.update({
last_modified_at: knex.client.config.client.includes('sqlite3')
? knex.raw(`datetime('now', '-3600 seconds')`)
: (
knex.client.config.client.includes('mysql')
? knex.raw(`date_sub(now(), interval 3600 second)`)
: knex.raw(`now() + interval '-3600 seconds'`)
),
last_modified_at: knex.raw(hourPast),
});
expect(updated).toBe(1);
@@ -138,16 +138,19 @@ export class StaticAssetsStore implements StaticAssetProvider {
*/
async trimAssets(options: { maxAgeSeconds: number }) {
const { maxAgeSeconds } = options;
let lastModifiedInterval = `now() + interval '${-maxAgeSeconds} seconds'`;
if (this.#db.client.config.client.includes('mysql')) {
lastModifiedInterval = `date_sub(now(), interval ${maxAgeSeconds} second)`;
} else if (this.#db.client.config.client.includes('sqlite3')) {
lastModifiedInterval = `datetime('now', ?)`;
}
await this.#db<StaticAssetRow>('static_assets_cache')
.where(
'last_modified_at',
'<=',
this.#db.client.config.client.includes('sqlite3')
? this.#db.raw(`datetime('now', ?)`, [`-${maxAgeSeconds} seconds`])
: (this.#db.client.config.client.includes('mysql')
? this.#db.raw(`date_sub(now(), interval ${maxAgeSeconds} second)`)
: this.#db.raw(`now() + interval '${-maxAgeSeconds} seconds'`)
),
? this.#db.raw(lastModifiedInterval, [`-${maxAgeSeconds} seconds`])
: this.#db.raw(lastModifiedInterval),
)
.delete();
}