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

Optimize fetching of augment-vis saved objects #562

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
Original file line number Diff line number Diff line change
Expand Up @@ -204,28 +204,32 @@ function AddAnomalyDetector({
const maxAssociatedCount = uiSettings.get(
PLUGIN_AUGMENTATION_MAX_OBJECTS_SETTING
);
await savedObjectLoader.findAll().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', '') === embeddable.vis.id
await savedObjectLoader
.findAll('', 100, [], {
type: 'visualization',
id: embeddable.vis.id as string,
})
.then(async (resp) => {
if (resp !== undefined) {
const savedObjectsForThisVisualization = get(
resp,
'hits',
[]
);
if (
maxAssociatedCount <= savedObjectsForThisVisualization.length
) {
notifications.toasts.addDanger(
`Cannot create the detector and associate it to the visualization due to the limit of the max
if (
maxAssociatedCount <=
savedObjectsForThisVisualization.length
) {
notifications.toasts.addDanger(
`Cannot create the detector and associate it to the visualization due to the limit of the max
amount of associated plugin resources (${maxAssociatedCount}) with
${savedObjectsForThisVisualization.length} associated to the visualization`
);
} else {
handleSubmit(formikProps);
);
} else {
handleSubmit(formikProps);
}
}
}
});
});
}
}
});
Expand All @@ -244,20 +248,21 @@ function AddAnomalyDetector({

useEffect(async () => {
// Gets all augmented saved objects
await savedObjectLoader.findAll().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', '') === embeddable.vis.id
);
if (maxAssociatedCount <= savedObjectsForThisVisualization.length) {
setAssociationLimitReached(true);
} else {
setAssociationLimitReached(false);
await savedObjectLoader
.findAll('', 100, [], {
type: 'visualization',
id: embeddable.vis.id as string,
})
.then(async (resp) => {
if (resp !== undefined) {
const savedObjectsForThisVisualization = get(resp, 'hits', []);
if (maxAssociatedCount <= savedObjectsForThisVisualization.length) {
setAssociationLimitReached(true);
} else {
setAssociationLimitReached(false);
}
}
}
});
});
}, []);

const getEmbeddableSection = () => {
Expand Down