Skip to content

Commit

Permalink
Optimize fetching of augment-vis saved objects (#659)
Browse files Browse the repository at this point in the history
* Optimize fetching of augment-vis saved objects

Signed-off-by: Ashish Agrawal <ashisagr@amazon.com>

* address comment

Signed-off-by: Ashish Agrawal <ashisagr@amazon.com>

---------

Signed-off-by: Ashish Agrawal <ashisagr@amazon.com>
  • Loading branch information
lezzago authored Jul 20, 2023
1 parent 18c5e1d commit 0dd05f8
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions public/utils/savedObjectHelper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});
};
Expand Down Expand Up @@ -119,17 +119,16 @@ export const deleteAlertingAugmentVisSavedObj = async (
monitorId: string
): Promise<void> => {
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', '');
Expand Down

0 comments on commit 0dd05f8

Please sign in to comment.