Skip to content

Commit

Permalink
✨ Optimize polling to only occur when a task is active (#1715)
Browse files Browse the repository at this point in the history
Addresses part of https://issues.redhat.com/browse/MTA-2359

Signed-off-by: Ian Bolton <ibolton@redhat.com>
  • Loading branch information
ibolton336 authored Mar 4, 2024
1 parent d77a79f commit 95b6ebc
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 @@ -147,7 +147,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 @@ -209,7 +212,7 @@ export const ApplicationsTable: React.FC = () => {
isFetching: isFetchingApplications,
error: applicationsFetchError,
refetch: fetchApplications,
} = useFetchApplications();
} = useFetchApplications(!hasActiveTasks);

const { assessments, isFetching: isFetchingAssesments } =
useFetchAssessments();
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 95b6ebc

Please sign in to comment.