From 0dd05f8eff0bc7de6381c688973dfa35df9ef582 Mon Sep 17 00:00:00 2001 From: Ashish Agrawal Date: Wed, 19 Jul 2023 19:20:30 -0700 Subject: [PATCH] Optimize fetching of augment-vis saved objects (#659) * Optimize fetching of augment-vis saved objects Signed-off-by: Ashish Agrawal * address comment Signed-off-by: Ashish Agrawal --------- Signed-off-by: Ashish Agrawal --- public/utils/savedObjectHelper.tsx | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/public/utils/savedObjectHelper.tsx b/public/utils/savedObjectHelper.tsx index 64c60646d..d9cb12715 100644 --- a/public/utils/savedObjectHelper.tsx +++ b/public/utils/savedObjectHelper.tsx @@ -51,14 +51,14 @@ export const validateAssociationIsAllow = async (visId, sendDangerToast = false) export const getCountOfAssociatedObjects = async (visId) => { const loader = getSavedAugmentVisLoader(); - return await loader.findAll().then(async (resp) => { + return await loader.findAll('', 100, [], { + type: 'visualization', + id: visId, + } + ).then(async (resp) => { if (resp !== undefined) { const savedAugmentObjects = get(resp, 'hits', []); - // gets all the saved object for this visualization - const savedObjectsForThisVisualization = savedAugmentObjects.filter( - (savedObj) => get(savedObj, 'visId', '') === visId - ); - return savedObjectsForThisVisualization.length; + return savedAugmentObjects.length; } }); }; @@ -119,17 +119,16 @@ export const deleteAlertingAugmentVisSavedObj = async ( monitorId: string ): Promise => { const savedObjectLoader = getSavedAugmentVisLoader(); - await savedObjectLoader.findAll().then(async (resp) => { + await savedObjectLoader.findAll('', 100, [], { + type: 'visualization', + id: visId, + } + ).then(async (resp) => { if (resp !== undefined) { const savedAugmentObjects = get(resp, 'hits', []); - // gets all the saved object for this visualization - const savedAugmentForThisVisualization = savedAugmentObjects.filter( - (savedObj) => get(savedObj, 'visId', '') === visId - ); - // find saved Augment object matching detector we want to unlink // There should only be one detector and vis pairing - const savedAugmentToUnlink = savedAugmentForThisVisualization.find( + const savedAugmentToUnlink = savedAugmentObjects.find( (savedObject) => get(savedObject, 'pluginResource.id', '') === monitorId ); const savedObjectToUnlinkId = get(savedAugmentToUnlink, 'id', '');