perf: skip offline runtime polling
This commit is contained in:
parent
e4483a3ad6
commit
322c63ea8b
2 changed files with 83 additions and 6 deletions
|
|
@ -6,6 +6,19 @@ import { useShallow } from 'zustand/react/shallow';
|
|||
|
||||
const TEAM_AGENT_RUNTIME_REFRESH_MS = 5_000;
|
||||
|
||||
export function shouldWatchTeamAgentRuntime(input: {
|
||||
enabled: boolean;
|
||||
isTeamProvisioning: boolean | undefined;
|
||||
isTeamAlive: boolean | undefined;
|
||||
leadActivity: 'active' | 'idle' | 'offline' | undefined;
|
||||
}): boolean {
|
||||
if (!input.enabled) return false;
|
||||
if (input.isTeamProvisioning) return true;
|
||||
if (input.isTeamAlive === true) return true;
|
||||
if (input.isTeamAlive === false) return false;
|
||||
return input.leadActivity === 'active' || input.leadActivity === 'idle';
|
||||
}
|
||||
|
||||
interface TeamAgentRuntimeWatcherOptions {
|
||||
teamName: string;
|
||||
enabled: boolean;
|
||||
|
|
@ -33,12 +46,12 @@ export function useTeamAgentRuntimeWatcher({
|
|||
const effectiveIsTeamProvisioning = isTeamProvisioning ?? storeIsTeamProvisioning;
|
||||
|
||||
useEffect(() => {
|
||||
if (!enabled) return;
|
||||
const shouldWatch =
|
||||
effectiveIsTeamProvisioning ||
|
||||
effectiveIsTeamAlive === true ||
|
||||
leadActivity === 'active' ||
|
||||
leadActivity === 'idle';
|
||||
const shouldWatch = shouldWatchTeamAgentRuntime({
|
||||
enabled,
|
||||
isTeamProvisioning: effectiveIsTeamProvisioning,
|
||||
isTeamAlive: effectiveIsTeamAlive,
|
||||
leadActivity,
|
||||
});
|
||||
if (!shouldWatch) return;
|
||||
|
||||
void fetchTeamAgentRuntime(teamName);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,64 @@
|
|||
import { shouldWatchTeamAgentRuntime } from '@renderer/components/team/useTeamAgentRuntimeWatcher';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
describe('shouldWatchTeamAgentRuntime', () => {
|
||||
it('does not poll runtime for explicitly offline teams with stale lead activity', () => {
|
||||
expect(
|
||||
shouldWatchTeamAgentRuntime({
|
||||
enabled: true,
|
||||
isTeamProvisioning: false,
|
||||
isTeamAlive: false,
|
||||
leadActivity: 'idle',
|
||||
})
|
||||
).toBe(false);
|
||||
expect(
|
||||
shouldWatchTeamAgentRuntime({
|
||||
enabled: true,
|
||||
isTeamProvisioning: false,
|
||||
isTeamAlive: false,
|
||||
leadActivity: 'active',
|
||||
})
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('keeps runtime polling for live and provisioning teams', () => {
|
||||
expect(
|
||||
shouldWatchTeamAgentRuntime({
|
||||
enabled: true,
|
||||
isTeamProvisioning: false,
|
||||
isTeamAlive: true,
|
||||
leadActivity: 'offline',
|
||||
})
|
||||
).toBe(true);
|
||||
expect(
|
||||
shouldWatchTeamAgentRuntime({
|
||||
enabled: true,
|
||||
isTeamProvisioning: true,
|
||||
isTeamAlive: false,
|
||||
leadActivity: 'offline',
|
||||
})
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('allows lead activity to request polling while liveness is still unknown', () => {
|
||||
expect(
|
||||
shouldWatchTeamAgentRuntime({
|
||||
enabled: true,
|
||||
isTeamProvisioning: false,
|
||||
isTeamAlive: undefined,
|
||||
leadActivity: 'idle',
|
||||
})
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('stays disabled for hidden tabs', () => {
|
||||
expect(
|
||||
shouldWatchTeamAgentRuntime({
|
||||
enabled: false,
|
||||
isTeamProvisioning: true,
|
||||
isTeamAlive: true,
|
||||
leadActivity: 'active',
|
||||
})
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue