Skip to content

Commit

Permalink
✨ Optimize polling to only occur when a task is active
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Bolton <ibolton@redhat.com>
  • Loading branch information
ibolton336 committed Feb 28, 2024
1 parent 59ad200 commit bae18ce
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ export const ApplicationsTable: React.FC = () => {
const getTask = (application: Application) =>
tasks.find((task: Task) => task.application?.id === application.id);

const { tasks } = useFetchTasks({ addon: "analyzer" }, isAnalyzeModalOpen);
const { tasks, hasActiveTasks } = useFetchTasks(
{ addon: "analyzer" },
isAnalyzeModalOpen
);

const isTaskCancellable = (application: Application) => {
const task = getTask(application);
Expand Down Expand Up @@ -205,7 +208,7 @@ export const ApplicationsTable: React.FC = () => {
isFetching: isFetchingApplications,
error: applicationsFetchError,
refetch: fetchApplications,
} = useFetchApplications();
} = useFetchApplications(!hasActiveTasks);

const onDeleteApplicationSuccess = (appIDCount: number) => {
pushNotification({
Expand Down
2 changes: 2 additions & 0 deletions client/src/app/queries/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ export const useFetchTasks = (
},
onError: (err) => console.log(err),
});
const hasActiveTasks = data && data.length > 0;

return {
tasks: data || [],
isFetching: isLoading,
fetchError: error,
refetch,
hasActiveTasks,
};
};

Expand Down

0 comments on commit bae18ce

Please sign in to comment.