From b959196381b7b4e3848ac0d5259e3c94527a4a4f Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 24 Mar 2026 09:28:31 +0000 Subject: [PATCH] refactor: deduplicate benchmark controller run methods into shared helper Extract common logic from runSystem() and runAI() into a private _runBenchmark() helper that handles checking for running benchmarks, dispatching the job, and returning the response. https://claude.ai/code/session_01JFvpTYgm8GiE4vJ4cJKsFx --- admin/app/controllers/benchmark_controller.ts | 35 +++++++------------ 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/admin/app/controllers/benchmark_controller.ts b/admin/app/controllers/benchmark_controller.ts index b3e5343..668c79a 100644 --- a/admin/app/controllers/benchmark_controller.ts +++ b/admin/app/controllers/benchmark_controller.ts @@ -81,32 +81,21 @@ export default class BenchmarkController { * Run a system-only benchmark (CPU, memory, disk) */ async runSystem({ response }: HttpContext) { - const status = this.benchmarkService.getStatus() - if (status.status !== 'idle') { - return response.status(409).send({ - success: false, - error: 'A benchmark is already running', - }) - } - - const benchmarkId = randomUUID() - await RunBenchmarkJob.dispatch({ - benchmark_id: benchmarkId, - benchmark_type: 'system', - include_ai: false, - }) - - return response.status(201).send({ - success: true, - benchmark_id: benchmarkId, - message: 'System benchmark started', - }) + return this._runBenchmark('system', response) } /** * Run an AI-only benchmark */ async runAI({ response }: HttpContext) { + return this._runBenchmark('ai', response) + } + + /** + * Shared helper for dispatching a benchmark job. + * Checks for existing running benchmarks, dispatches the job, and returns the response. + */ + private async _runBenchmark(type: BenchmarkType, response: HttpContext['response']) { const status = this.benchmarkService.getStatus() if (status.status !== 'idle') { return response.status(409).send({ @@ -118,14 +107,14 @@ export default class BenchmarkController { const benchmarkId = randomUUID() await RunBenchmarkJob.dispatch({ benchmark_id: benchmarkId, - benchmark_type: 'ai', - include_ai: true, + benchmark_type: type, + include_ai: type === 'full' || type === 'ai', }) return response.status(201).send({ success: true, benchmark_id: benchmarkId, - message: 'AI benchmark started', + message: `${type === 'ai' ? 'AI' : type.charAt(0).toUpperCase() + type.slice(1)} benchmark started`, }) }