From abfbb0f27916338db5e3d7f4b37da70d0dc0df35 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Sat, 7 Jan 2023 17:22:14 +0100 Subject: [PATCH] Restored showcased function with indexes. --- assets/js/fragments.js | 20 ++------- .../20230104014437_release_showcased.js | 42 +++++++++---------- 2 files changed, 23 insertions(+), 39 deletions(-) diff --git a/assets/js/fragments.js b/assets/js/fragments.js index 600dcb70..5d119569 100755 --- a/assets/js/fragments.js +++ b/assets/js/fragments.js @@ -431,22 +431,10 @@ 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 index 4ea0a9b9..0cd91f14 100644 --- a/migrations/20230104014437_release_showcased.js +++ b/migrations/20230104014437_release_showcased.js @@ -1,24 +1,20 @@ -/* -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; -`); +exports.up = async (knex) => Promise.resolve() + .then(() => 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; + `)).then(() => knex.schema.alterTable('releases', (table) => { + table.index('entity_id'); + table.index('studio_id'); + })); -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'); -}); +exports.down = async (knex) => Promise.resolve() + .then(() => knex.schema.alterTable('releases', (table) => { + table.dropIndex('entity_id'); + table.dropIndex('studio_id'); + })).then(() => knex.raw(` + DROP FUNCTION IF EXISTS releases_is_showcased; + `));