From 16b4d4a6ba14bd05a3aed83bd8c0feef8f9c7bb2 Mon Sep 17 00:00:00 2001 From: csmig Date: Fri, 6 Sep 2024 18:25:15 -0400 Subject: [PATCH] refactor: better joins in getCollectionLabels() --- api/source/service/CollectionService.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/api/source/service/CollectionService.js b/api/source/service/CollectionService.js index b71c350a..f2a9a300 100644 --- a/api/source/service/CollectionService.js +++ b/api/source/service/CollectionService.js @@ -1306,16 +1306,13 @@ exports.getCollectionLabels = async function (collectionId, userObject) { 'collection_label cl', 'inner join collection c on c.collectionId = cl.collectionId and c.state = "enabled"', 'left join collection_grant cg_l on cl.collectionId = cg_l.collectionId', - 'left join asset a_l on cl.collectionId = a_l.collectionId', + 'left join collection_label_asset_map cla on cla.clId = cl.clId', + 'left join asset a_l on cla.assetId = a_l.assetId and a_l.state = "enabled"', 'left join stig_asset_map sa_l on a_l.assetId = sa_l.assetId', - 'left join user_stig_asset_map usa_l on sa_l.saId = usa_l.saId', - 'left join collection_label_asset_map cla on cla.clId = cl.clId and cla.assetId = a_l.assetId and a_l.state = "enabled"' + 'left join user_stig_asset_map usa_l on sa_l.saId = usa_l.saId' ] const groupBy = [ - 'cl.uuid', - 'cl.name', - 'cl.description', - 'cl.color' + 'cl.clId' ] const predicates = { statements: [