mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-16 14:16:16 -08:00
* docs(performance): plan Xtream benchmark * feat(xtream-mock-server): add deterministic 100k fixture * style(xtream-mock-server): apply repository formatting * fix(xtream-mock-server): harden performance fixture data * feat(xtream-mock-server): add performance control plane * docs(performance): correct Xtream capture plan * fix(xtream-mock-server): harden performance controls * fix(xtream-mock-server): harden control lifecycle * feat(performance): add Xtream preload markers * feat(performance): trace Xtream main phases * feat(performance): mark Xtream store publications * feat(performance): trace Xtream database phases * feat(performance): trace Xtream delete cancellation * feat(performance): capture Xtream phase attribution * feat(performance): mark Sources Xtream refresh * test(performance): define Xtream benchmark evidence contracts * test(performance): add Xtream benchmark runner * test(performance): surface failure evidence writes * test(performance): align database read clock * test(performance): preserve capture failure contracts
69 lines
2.3 KiB
TypeScript
69 lines
2.3 KiB
TypeScript
import type {
|
|
XtreamDatabasePerformancePhase,
|
|
PerformancePhaseMetadata,
|
|
} from '@iptvnator/shared/interfaces';
|
|
import type { DatabaseOperationPerformancePhaseCapture } from './performance-phase-capture';
|
|
|
|
export interface RecordedOperationPhase {
|
|
readonly boundary: 'end' | 'start';
|
|
readonly metadata?: PerformancePhaseMetadata;
|
|
readonly phase: XtreamDatabasePerformancePhase;
|
|
}
|
|
|
|
export function createRecordingOperationPhaseCapture(
|
|
onBoundary?: (event: RecordedOperationPhase) => void
|
|
): {
|
|
readonly capture: DatabaseOperationPerformancePhaseCapture;
|
|
readonly events: RecordedOperationPhase[];
|
|
} {
|
|
const events: RecordedOperationPhase[] = [];
|
|
const record = (event: RecordedOperationPhase): void => {
|
|
events.push(event);
|
|
onBoundary?.(event);
|
|
};
|
|
|
|
return {
|
|
capture: {
|
|
async captureAsync<TResult>(
|
|
phase: XtreamDatabasePerformancePhase,
|
|
execute: () => Promise<TResult>,
|
|
metadata?: (result: TResult) => PerformancePhaseMetadata
|
|
): Promise<TResult> {
|
|
record({ boundary: 'start', phase });
|
|
try {
|
|
const result = await execute();
|
|
record({
|
|
boundary: 'end',
|
|
metadata: metadata?.(result),
|
|
phase,
|
|
});
|
|
return result;
|
|
} catch (error) {
|
|
record({ boundary: 'end', phase });
|
|
throw error;
|
|
}
|
|
},
|
|
captureSync<TResult>(
|
|
phase: XtreamDatabasePerformancePhase,
|
|
execute: () => TResult,
|
|
metadata?: (result: TResult) => PerformancePhaseMetadata
|
|
): TResult {
|
|
record({ boundary: 'start', phase });
|
|
try {
|
|
const result = execute();
|
|
record({
|
|
boundary: 'end',
|
|
metadata: metadata?.(result),
|
|
phase,
|
|
});
|
|
return result;
|
|
} catch (error) {
|
|
record({ boundary: 'end', phase });
|
|
throw error;
|
|
}
|
|
},
|
|
},
|
|
events,
|
|
};
|
|
}
|