mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-02 03:55:55 +00:00
fix(web): stop polling plugin tasks when no active installs
The PluginInstallTaskProvider was unconditionally polling getAsyncTasks every 3s on all /home/* routes. Now it only syncs once on mount and starts periodic polling only when there are active (non-terminal) install tasks.
This commit is contained in:
@@ -401,14 +401,32 @@ export function PluginInstallTaskProvider({
|
||||
}
|
||||
}, [pollTask]);
|
||||
|
||||
// Initial sync on mount + periodic sync every 3s
|
||||
// Initial sync on mount to recover any orphaned tasks
|
||||
const syncOnMountRef = useRef(syncTasksFromBackend);
|
||||
syncOnMountRef.current = syncTasksFromBackend;
|
||||
useEffect(() => {
|
||||
syncTasksFromBackend();
|
||||
syncOnMountRef.current();
|
||||
}, []);
|
||||
|
||||
// Only poll periodically when there are active (non-terminal) tasks
|
||||
useEffect(() => {
|
||||
const hasActiveTasks = tasks.some(
|
||||
(t) => t.stage !== InstallStage.DONE && t.stage !== InstallStage.ERROR,
|
||||
);
|
||||
|
||||
if (hasActiveTasks) {
|
||||
syncIntervalRef.current = setInterval(syncTasksFromBackend, 3000);
|
||||
} else {
|
||||
if (syncIntervalRef.current) {
|
||||
clearInterval(syncIntervalRef.current);
|
||||
syncIntervalRef.current = null;
|
||||
}
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (syncIntervalRef.current) clearInterval(syncIntervalRef.current);
|
||||
};
|
||||
}, [syncTasksFromBackend]);
|
||||
}, [tasks, syncTasksFromBackend]);
|
||||
|
||||
const addTask = useCallback(
|
||||
(params: {
|
||||
|
||||
Reference in New Issue
Block a user