Skip to content

Commit

Permalink
Eager load all the related items at once
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofandel authored and ifox committed Oct 21, 2024
1 parent 73bfbdd commit 9c6416f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
2 changes: 0 additions & 2 deletions src/Repositories/Behaviors/HandleRevisions.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,8 @@ public function hydrateRelatedBrowsers(TwillModelContract $object, array $fields

foreach ($relatedBrowsers as $browser) {
$browserField = $fields['browsers'][$browser['browserName']] ?? [];

$position = 1;
foreach ($browserField as $values) {

$relatedBrowserItems->push(new RelatedItem([
'subject_id' => $object->getKey(),
'subject_type' => $object->getMorphClass(),
Expand Down
5 changes: 2 additions & 3 deletions src/Repositories/BlockRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ public function hydrate(TwillModelContract $model, array $fields): TwillModelCon
'related_type' => $item['endpointType'],
'browser_name' => $browserName,
'position' => $position,
])
)
);
])));

$model->setRelation('relatedItems', $relatedItems);
$model->loadMissing('relatedItems.related');

return parent::hydrate($model, $fields);
}
Expand Down

0 comments on commit 9c6416f

Please sign in to comment.