From 250618df8b1a931a5e5d8b5dcf9bce2a8226b014 Mon Sep 17 00:00:00 2001 From: DebaucheryLibrarian Date: Wed, 26 Jan 2022 13:52:39 +0100 Subject: [PATCH] Added entity scene count function. --- assets/js/curate.js | 4 +--- assets/js/entities/actions.js | 4 +--- migrations/20220126132955_scene_counts.js | 11 +++++++++++ 3 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 migrations/20220126132955_scene_counts.js diff --git a/assets/js/curate.js b/assets/js/curate.js index bf6d236c1..2d5a94117 100644 --- a/assets/js/curate.js +++ b/assets/js/curate.js @@ -117,9 +117,7 @@ function curateEntity(entity, parent, releases) { if (entity.parent || parent) curatedEntity.parent = curateEntity(entity.parent || parent); if (releases) curatedEntity.releases = releases.map((release) => curateRelease(release)); - if (entity.connection) { - curatedEntity.sceneTotal = entity.connection.totalCount; - } + curatedEntity.sceneTotal = entity.sceneTotal; return curatedEntity; } diff --git a/assets/js/entities/actions.js b/assets/js/entities/actions.js index 88ad3c4a7..b49e97568 100644 --- a/assets/js/entities/actions.js +++ b/assets/js/entities/actions.js @@ -62,12 +62,10 @@ function initEntitiesActions(store, router) { independent hasLogo ${campaignsFragment} + sceneTotal children: childEntitiesConnection { totalCount } - connection: scenesConnection { - totalCount - } } } ${campaignsFragment} diff --git a/migrations/20220126132955_scene_counts.js b/migrations/20220126132955_scene_counts.js new file mode 100644 index 000000000..ae58bce0d --- /dev/null +++ b/migrations/20220126132955_scene_counts.js @@ -0,0 +1,11 @@ +exports.up = async (knex) => knex.raw(` + CREATE OR REPLACE FUNCTION entities_scene_total(entity entities) RETURNS integer AS $$ + SELECT COUNT(id) + FROM releases + WHERE releases.entity_id = entity.id; + $$ LANGUAGE SQL STABLE; +`); + +exports.down = async (knex) => knex.raw(` + DROP FUNCTION IF EXISTS entities_scene_total; +`);