Skip to content

Commit 5ed95a6

Browse files
Bulk insert test measurements (#3653)
Test measurements are currently saved individually, resulting in O(#tests * #measurements) round-trips to the database for each submission processed. This improves the situation, bulk inserting the measurements instead. There's more work to be done here, but I want to see how well this performs first.
1 parent 3861fd2 commit 5ed95a6

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

app/Utils/TestCreator.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
use App\Models\Test;
2121
use App\Models\TestImage;
22+
use App\Models\TestMeasurement;
2223
use App\Models\TestOutput;
2324
use Carbon\Carbon;
2425
use CDash\Model\Build;
@@ -157,9 +158,18 @@ public function create(Build $build): void
157158
'starttime' => $this->testStartTime,
158159
]);
159160

160-
foreach ($this->measurements as $measurement) {
161-
$measurement->testid = $buildtest->id;
162-
$measurement->save();
161+
if ($this->measurements->isNotEmpty()) {
162+
// Bulk inserting test measurements is more efficient than individual saves.
163+
$measurements = $this->measurements->map(fn ($measurement) => [
164+
'testid' => $buildtest->id,
165+
'name' => $measurement->name,
166+
'type' => $measurement->type,
167+
'value' => $measurement->value,
168+
])->toArray();
169+
TestMeasurement::insert($measurements);
170+
171+
// Reload the test measurements so we can pass them downstream to compute the proc time.
172+
$this->measurements = $buildtest->testMeasurements;
163173
}
164174

165175
// Give measurements to the buildtest model so we can properly calculate

0 commit comments

Comments
 (0)