Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.9] Optimize fetching of augment-vis saved objects #661

Merged
merged 1 commit into from
Jul 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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