CreateImageWizard: on-prem prefetch

The openscap customizatoins endpoint for on-prem is quite slow since it
has to call the run the oscap tool to generate the customization
options. Running this request lazily, as we do for the service, is too
slow, so we can just prefetch the customizations for on-prem.
This commit is contained in:
Gianluca Zuccarelli 2025-03-21 14:12:28 +00:00 committed by Lucas Garfield
parent 18c329be2a
commit 20447f753a

View file

@ -29,6 +29,7 @@ import {
useGetOscapProfilesQuery,
useGetOscapCustomizationsQuery,
useLazyGetOscapCustomizationsQuery,
useBackendPrefetch,
} from '../../../../store/backendApi';
import { usePoliciesQuery, PolicyRead } from '../../../../store/complianceApi';
import { useAppDispatch, useAppSelector } from '../../../../store/hooks';
@ -99,6 +100,7 @@ const ProfileSelector = () => {
const dispatch = useAppDispatch();
const [isOpen, setIsOpen] = useState(false);
const complianceType = useAppSelector(selectComplianceType);
const prefetchProfile = useBackendPrefetch('getOscapCustomizations');
const {
data: profiles,
@ -139,6 +141,18 @@ const ProfileSelector = () => {
const [trigger] = useLazyGetOscapCustomizationsQuery();
// prefetch the profiles customizations for on-prem
// and save the results to the cache, since the request
// is quite slow
if (process.env.IS_ON_PREMISE) {
profiles?.forEach((profile) => {
prefetchProfile({
distribution: release,
profile: profile,
});
});
}
useEffect(() => {
if (!policies || policies.data === undefined) {
return;