perf(history): reduce export polling load
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { buildHistoryChartSeries, buildHistorySeriesPanels, formatExportFileSize, formatHistoryValue, parseHistoryKeywords } from './history';
|
||||
import { buildHistoryChartSeries, buildHistorySeriesPanels, formatExportFileSize, formatHistoryValue, HISTORY_EXPORT_POLL_MS, historyExportPollInterval, parseHistoryKeywords } from './history';
|
||||
|
||||
describe('history domain', () => {
|
||||
it('parses and bounds multi-vehicle input', () => {
|
||||
@@ -41,4 +41,12 @@ describe('history domain', () => {
|
||||
expect(formatExportFileSize(1536)).toBe('1.5 KB');
|
||||
expect(formatExportFileSize(5 * 1024 * 1024)).toBe('5.0 MB');
|
||||
});
|
||||
|
||||
it('polls active export jobs conservatively and stops after terminal states', () => {
|
||||
expect(historyExportPollInterval([{ status: 'running' }])).toBe(HISTORY_EXPORT_POLL_MS.running);
|
||||
expect(historyExportPollInterval([{ status: 'queued' }])).toBe(HISTORY_EXPORT_POLL_MS.queued);
|
||||
expect(historyExportPollInterval([{ status: 'queued' }, { status: 'running' }])).toBe(HISTORY_EXPORT_POLL_MS.running);
|
||||
expect(historyExportPollInterval([{ status: 'completed' }, { status: 'failed' }])).toBe(false);
|
||||
expect(historyExportPollInterval()).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,15 @@
|
||||
import type { HistoryDataRow, HistoryMetricDefinition, HistorySeries, HistorySeriesResponse } from '../../api/types';
|
||||
import type { HistoryDataRow, HistoryExportJob, HistoryMetricDefinition, HistorySeries, HistorySeriesResponse } from '../../api/types';
|
||||
|
||||
export const HISTORY_EXPORT_POLL_MS = {
|
||||
running: 3_000,
|
||||
queued: 5_000
|
||||
} as const;
|
||||
|
||||
export function historyExportPollInterval(jobs?: Array<Pick<HistoryExportJob, 'status'>>) {
|
||||
if (jobs?.some((job) => job.status === 'running')) return HISTORY_EXPORT_POLL_MS.running;
|
||||
if (jobs?.some((job) => job.status === 'queued')) return HISTORY_EXPORT_POLL_MS.queued;
|
||||
return false;
|
||||
}
|
||||
|
||||
export function parseHistoryKeywords(value: string) {
|
||||
const seen = new Set<string>();
|
||||
|
||||
Reference in New Issue
Block a user