From 5133336094ee62a6028052ddb3b2d9b0d5de37ac Mon Sep 17 00:00:00 2001 From: William Allen Date: Mon, 9 Mar 2026 09:11:45 -0400 Subject: [PATCH 1/4] Only select test output ID instead of entire model --- app/Utils/TestCreator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Utils/TestCreator.php b/app/Utils/TestCreator.php index 2d3e239765..5114c99837 100755 --- a/app/Utils/TestCreator.php +++ b/app/Utils/TestCreator.php @@ -136,7 +136,7 @@ public function create(Build $build): void } } - $outputid = TestOutput::firstOrCreate([ + $outputid = TestOutput::select('id')->firstOrCreate([ 'path' => $this->testPath, 'command' => $this->testCommand, 'output' => $this->testOutput, From c2c352172d986dbe67ac69dba098f200f9e3283b Mon Sep 17 00:00:00 2001 From: William Allen Date: Mon, 9 Mar 2026 09:14:25 -0400 Subject: [PATCH 2/4] Wrap create() in transaction This avoids needing to commit many small transactions, while also giving us consistency for free. --- app/Utils/TestCreator.php | 79 ++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/app/Utils/TestCreator.php b/app/Utils/TestCreator.php index 5114c99837..7242e6c8f5 100755 --- a/app/Utils/TestCreator.php +++ b/app/Utils/TestCreator.php @@ -24,6 +24,7 @@ use CDash\Model\Build; use CDash\Model\Image; use ErrorException; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; /** @@ -136,46 +137,48 @@ public function create(Build $build): void } } - $outputid = TestOutput::select('id')->firstOrCreate([ - 'path' => $this->testPath, - 'command' => $this->testCommand, - 'output' => $this->testOutput, - ])->id; - - // build2test - $buildtest = new Test(); - $buildtest->buildid = $build->Id; - $buildtest->outputid = $outputid; - $buildtest->status = $this->testStatus; - $buildtest->details = $this->testDetails; - $buildtest->time = "$this->buildTestTime"; - $buildtest->testname = $this->testName; - $buildtest->starttime = $this->testStartTime; - - // Note: the newstatus column is currently handled in - // ctestparserutils::compute_test_difference. This gets updated when we call - // Build::ComputeTestTiming. - $buildtest->save(); - - foreach ($this->measurements as $measurement) { - $measurement->testid = $buildtest->id; - $measurement->save(); - } + DB::transaction(function () use ($build) { + $outputid = TestOutput::select('id')->firstOrCreate([ + 'path' => $this->testPath, + 'command' => $this->testCommand, + 'output' => $this->testOutput, + ])->id; + + // build2test + $buildtest = new Test(); + $buildtest->buildid = $build->Id; + $buildtest->outputid = $outputid; + $buildtest->status = $this->testStatus; + $buildtest->details = $this->testDetails; + $buildtest->time = "$this->buildTestTime"; + $buildtest->testname = $this->testName; + $buildtest->starttime = $this->testStartTime; + + // Note: the newstatus column is currently handled in + // ctestparserutils::compute_test_difference. This gets updated when we call + // Build::ComputeTestTiming. + $buildtest->save(); + + foreach ($this->measurements as $measurement) { + $measurement->testid = $buildtest->id; + $measurement->save(); + } - // Give measurements to the buildtest model so we can properly calculate - // proctime later on. - $buildtest->measurements = $this->measurements; - $build->AddTest($buildtest); + // Give measurements to the buildtest model so we can properly calculate + // proctime later on. + $buildtest->measurements = $this->measurements; + $build->AddTest($buildtest); - foreach ($this->labels as $label) { - $label->Test = $buildtest; - $label->Insert(); - $buildtest->addLabel($label); - } + foreach ($this->labels as $label) { + $label->Test = $buildtest; + $label->Insert(); + $buildtest->addLabel($label); + } - // test2image - foreach ($this->images as $image) { - $this->saveImage($image, $buildtest->id); - } + // test2image + foreach ($this->images as $image) { + $this->saveImage($image, $buildtest->id); + } + }); } } From 1a1e6bebc84d0b8a635a35429517c246a82cf0ec Mon Sep 17 00:00:00 2001 From: William Allen Date: Mon, 9 Mar 2026 09:15:40 -0400 Subject: [PATCH 3/4] Minor code cleanup, no performance benefit --- app/Utils/TestCreator.php | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/app/Utils/TestCreator.php b/app/Utils/TestCreator.php index 7242e6c8f5..976349d01e 100755 --- a/app/Utils/TestCreator.php +++ b/app/Utils/TestCreator.php @@ -144,20 +144,18 @@ public function create(Build $build): void 'output' => $this->testOutput, ])->id; - // build2test - $buildtest = new Test(); - $buildtest->buildid = $build->Id; - $buildtest->outputid = $outputid; - $buildtest->status = $this->testStatus; - $buildtest->details = $this->testDetails; - $buildtest->time = "$this->buildTestTime"; - $buildtest->testname = $this->testName; - $buildtest->starttime = $this->testStartTime; - // Note: the newstatus column is currently handled in // ctestparserutils::compute_test_difference. This gets updated when we call // Build::ComputeTestTiming. - $buildtest->save(); + $buildtest = Test::create([ + 'buildid' => $build->Id, + 'outputid' => $outputid, + 'status' => $this->testStatus, + 'details' => $this->testDetails, + 'time' => "$this->buildTestTime", + 'testname' => $this->testName, + 'starttime' => $this->testStartTime, + ]); foreach ($this->measurements as $measurement) { $measurement->testid = $buildtest->id; From c9b076afc95ef8fd8d655857968562cc797a50d5 Mon Sep 17 00:00:00 2001 From: William Allen Date: Mon, 9 Mar 2026 09:49:16 -0400 Subject: [PATCH 4/4] Lint --- app/Utils/TestCreator.php | 2 +- phpstan-baseline.neon | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/app/Utils/TestCreator.php b/app/Utils/TestCreator.php index 976349d01e..a4c8b42e96 100755 --- a/app/Utils/TestCreator.php +++ b/app/Utils/TestCreator.php @@ -137,7 +137,7 @@ public function create(Build $build): void } } - DB::transaction(function () use ($build) { + DB::transaction(function () use ($build): void { $outputid = TestOutput::select('id')->firstOrCreate([ 'path' => $this->testPath, 'command' => $this->testCommand, diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 761d5a7843..1231fd901c 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -7050,12 +7050,6 @@ parameters: count: 1 path: app/Utils/TestCreator.php - - - rawMessage: 'Property App\Models\Test::$time (float) does not accept string.' - identifier: assign.propertyType - count: 1 - path: app/Utils/TestCreator.php - - rawMessage: Property App\Utils\TestCreator::$alreadyCompressed has no type specified. identifier: missingType.property