From c5201e37eed364ff3ef1ae0b37a1d1fc5d5d3c34 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Wed, 4 Jan 2023 02:11:12 +0100 Subject: [PATCH] Moved showcase filter to computed column function. --- assets/js/fragments.js | 19 +++---------------- .../20230104014437_release_showcased.js | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 16 deletions(-) create mode 100644 migrations/20230104014437_release_showcased.js diff --git a/assets/js/fragments.js b/assets/js/fragments.js index 600dcb70..2519f053 100755 --- a/assets/js/fragments.js +++ b/assets/js/fragments.js @@ -431,22 +431,9 @@ const releasesFragment = ` } } } - or: [ - { - entity: { - showcased: { - equalTo: true - } - } - } - { - studio: { - showcased: { - equalTo: true - } - } - } - ] + isShowcased: { + equalTo: true + } }, first: $limit, offset: $offset, diff --git a/migrations/20230104014437_release_showcased.js b/migrations/20230104014437_release_showcased.js new file mode 100644 index 00000000..58305b2b --- /dev/null +++ b/migrations/20230104014437_release_showcased.js @@ -0,0 +1,18 @@ +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 + LEFT JOIN entities ON entities.id = releases.entity_id + 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; +`);