From f62a64c021468938f61d15b38ae128d5487a6204 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Sat, 7 Jan 2023 17:11:25 +0100 Subject: [PATCH] Added indeces on releases entity_id and studio_id, restored showcase query. --- assets/js/fragments.js | 19 ++++++++++++++++--- .../20230104014437_release_showcased.js | 18 ++++++++++++------ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/assets/js/fragments.js b/assets/js/fragments.js index 2519f053..600dcb70 100755 --- a/assets/js/fragments.js +++ b/assets/js/fragments.js @@ -431,9 +431,22 @@ const releasesFragment = ` } } } - isShowcased: { - equalTo: true - } + or: [ + { + entity: { + showcased: { + equalTo: true + } + } + } + { + studio: { + showcased: { + equalTo: true + } + } + } + ] }, first: $limit, offset: $offset, diff --git a/migrations/20230104014437_release_showcased.js b/migrations/20230104014437_release_showcased.js index 18e50618..4ea0a9b9 100644 --- a/migrations/20230104014437_release_showcased.js +++ b/migrations/20230104014437_release_showcased.js @@ -1,3 +1,4 @@ +/* exports.up = async (knex) => knex.raw(` CREATE FUNCTION releases_is_showcased(release releases) RETURNS BOOLEAN AS $$ SELECT COALESCE(entities.showcased, false) OR COALESCE(studios.showcased, false) FROM releases @@ -5,14 +6,19 @@ exports.up = async (knex) => knex.raw(` LEFT JOIN entities AS studios ON studios.id = releases.studio_id WHERE releases.id = release.id $$ LANGUAGE SQL STABLE; - - /* CREATE FUNCTION releases_is_showcased(release releases) RETURNS BOOLEAN AS $$ - SELECT COALESCE((SELECT showcased FROM entities WHERE entities.id = releases.entity_id), false) - OR COALESCE((SELECT showcased FROM entities WHERE entities.id = releases.studio_id), false) FROM releases - WHERE releases.id = release.id - $$ LANGUAGE SQL STABLE; */ `); exports.down = async (knex) => knex.raw(` DROP FUNCTION IF EXISTS releases_is_showcased; `); +*/ + +exports.up = async (knex) => knex.schema.alterTable('releases', (table) => { + table.index('entity_id'); + table.index('studio_id'); +}); + +exports.down = async (knex) => knex.schema.alterTable('releases', (table) => { + table.dropIndex('entity_id'); + table.dropIndex('studio_id'); +});