From 02cedae992a07a98ff188e45af1d97acc3b5b675 Mon Sep 17 00:00:00 2001 From: "lpete@vmware.com" Date: Mon, 7 Aug 2023 13:56:31 -0400 Subject: [PATCH] fix linting and prettier issues Signed-off-by: lpete@vmware.com --- .github/workflows/test-db.yml | 25 +++++++++---------- .../migrations/20211229105307_init.js | 6 ++++- .../src/lib/assets/StaticAssetsStore.test.ts | 16 ++++++------ .../src/lib/assets/StaticAssetsStore.ts | 13 ++++++---- 4 files changed, 33 insertions(+), 27 deletions(-) diff --git a/.github/workflows/test-db.yml b/.github/workflows/test-db.yml index 89822efffd..515eb64620 100644 --- a/.github/workflows/test-db.yml +++ b/.github/workflows/test-db.yml @@ -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 diff --git a/plugins/app-backend/migrations/20211229105307_init.js b/plugins/app-backend/migrations/20211229105307_init.js index 33fccd336d..859fc99a14 100644 --- a/plugins/app-backend/migrations/20211229105307_init.js +++ b/plugins/app-backend/migrations/20211229105307_init.js @@ -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()) diff --git a/plugins/app-backend/src/lib/assets/StaticAssetsStore.test.ts b/plugins/app-backend/src/lib/assets/StaticAssetsStore.test.ts index 21e86562c6..68fe4e2287 100644 --- a/plugins/app-backend/src/lib/assets/StaticAssetsStore.test.ts +++ b/plugins/app-backend/src/lib/assets/StaticAssetsStore.test.ts @@ -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); diff --git a/plugins/app-backend/src/lib/assets/StaticAssetsStore.ts b/plugins/app-backend/src/lib/assets/StaticAssetsStore.ts index 25606575cd..c2cfc471fb 100644 --- a/plugins/app-backend/src/lib/assets/StaticAssetsStore.ts +++ b/plugins/app-backend/src/lib/assets/StaticAssetsStore.ts @@ -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('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(); }