From 95b6ebc0200d2b0fbf894242f5b7bb53961ff00d Mon Sep 17 00:00:00 2001 From: Ian Bolton Date: Mon, 4 Mar 2024 16:44:55 -0500 Subject: [PATCH] :sparkles: Optimize polling to only occur when a task is active (#1715) Addresses part of https://issues.redhat.com/browse/MTA-2359 Signed-off-by: Ian Bolton --- .../applications/applications-table/applications-table.tsx | 7 +++++-- client/src/app/queries/tasks.ts | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/client/src/app/pages/applications/applications-table/applications-table.tsx b/client/src/app/pages/applications/applications-table/applications-table.tsx index 26c9b4d4dc..4f44be86ea 100644 --- a/client/src/app/pages/applications/applications-table/applications-table.tsx +++ b/client/src/app/pages/applications/applications-table/applications-table.tsx @@ -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); @@ -209,7 +212,7 @@ export const ApplicationsTable: React.FC = () => { isFetching: isFetchingApplications, error: applicationsFetchError, refetch: fetchApplications, - } = useFetchApplications(); + } = useFetchApplications(!hasActiveTasks); const { assessments, isFetching: isFetchingAssesments } = useFetchAssessments(); diff --git a/client/src/app/queries/tasks.ts b/client/src/app/queries/tasks.ts index 23d107a911..c2532f1ace 100644 --- a/client/src/app/queries/tasks.ts +++ b/client/src/app/queries/tasks.ts @@ -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, }; };