perf(renderer): slow task refreshes during launch

This commit is contained in:
777genius 2026-05-30 22:57:41 +03:00
parent c2ab7a7ff4
commit 8f1e223d61
2 changed files with 36 additions and 1 deletions

View file

@ -363,6 +363,7 @@ export function initializeNotificationListeners(): () => void {
const TEAM_MEMBER_SPAWN_REFRESH_THROTTLE_MS = 500;
const TEAM_LIST_REFRESH_THROTTLE_MS = 2000;
const GLOBAL_TASKS_REFRESH_THROTTLE_MS = 500;
const GLOBAL_TASKS_REFRESH_DURING_LAUNCH_THROTTLE_MS = 5000;
const PROCESS_LITE_STRUCTURAL_RECONCILE_IDLE_MS = 2_500;
const PROCESS_LITE_STRUCTURAL_RECONCILE_MAX_WAIT_MS = 15_000;
const buildTeamChangeFanoutReason = (eventType: string): string => `event:${eventType}`;
@ -2054,6 +2055,11 @@ export function initializeNotificationListeners(): () => void {
// Throttled refresh of global tasks list for sidebar.
if (shouldRefreshGlobalTasks) {
const globalTasksRefreshDelayMs = shouldDeferAutomaticTeamDataRefreshDuringLaunch(
event.teamName
)
? GLOBAL_TASKS_REFRESH_DURING_LAUNCH_THROTTLE_MS
: GLOBAL_TASKS_REFRESH_THROTTLE_MS;
noteGlobalRefreshScheduled(
pendingGlobalTasksRefreshDiagnostics,
event.teamName,
@ -2069,7 +2075,7 @@ export function initializeNotificationListeners(): () => void {
'fetchAllTasks'
);
void useStore.getState().fetchAllTasks();
}, GLOBAL_TASKS_REFRESH_THROTTLE_MS);
}, globalTasksRefreshDelayMs);
}
}

View file

@ -1101,6 +1101,35 @@ describe('team change throttling', () => {
expect(snapshot?.counts['team-change-listener:event:config:fetchAllTasks:executed']).toBe(1);
});
it('slows global task refreshes during active provisioning', async () => {
const fetchAllTasksSpy = vi.fn(async () => undefined);
useStore.setState({
fetchAllTasks: fetchAllTasksSpy,
currentProvisioningRunIdByTeam: { 'my-team': 'run-1' },
provisioningRuns: {
'run-1': {
runId: 'run-1',
teamName: 'my-team',
state: 'spawning',
message: 'Spawning',
startedAt: '2026-05-03T00:00:00.000Z',
updatedAt: '2026-05-03T00:00:00.000Z',
},
},
} as never);
await vi.advanceTimersByTimeAsync(5000);
fetchAllTasksSpy.mockClear();
hoisted.onTeamChangeCb?.({}, { type: 'task', teamName: 'my-team' });
await vi.advanceTimersByTimeAsync(4999);
expect(fetchAllTasksSpy).not.toHaveBeenCalled();
await vi.advanceTimersByTimeAsync(1);
expect(fetchAllTasksSpy).toHaveBeenCalledTimes(1);
});
it('lead-message refreshes message head only, not team list, tasks, or structural detail', async () => {
const state = useStore.getState();
const fetchTeamsSpy = vi.spyOn(state, 'fetchTeams');