diff --git a/app/Entities/Tools/EntityHydrator.php b/app/Entities/Tools/EntityHydrator.php index fbfc8762e..cb6267423 100644 --- a/app/Entities/Tools/EntityHydrator.php +++ b/app/Entities/Tools/EntityHydrator.php @@ -37,7 +37,7 @@ class EntityHydrator $hydrated = []; foreach ($this->entities as $entity) { - $data = $entity->toArray(); + $data = $entity->getRawOriginal(); $instance = Entity::instanceFromType($entity->type); if ($instance instanceof Page) { @@ -45,7 +45,7 @@ class EntityHydrator unset($data['description']); } - $instance->forceFill($data); + $instance = $instance->setRawAttributes($data, true); $hydrated[] = $instance; } @@ -131,7 +131,8 @@ class EntityHydrator } }); - $parents = $filtered ? (new EntityHydrator($parentQuery->get()->all()))->hydrate() : []; + $parentModels = $filtered ? $parentQuery->get()->all() : []; + $parents = (new EntityHydrator($parentModels))->hydrate(); $parentMap = []; foreach ($parents as $parent) { $parentMap[$parent->type . ':' . $parent->id] = $parent; @@ -139,12 +140,12 @@ class EntityHydrator foreach ($entities as $entity) { if ($entity instanceof Page || $entity instanceof Chapter) { - $key = 'book:' . $entity->getAttribute('book_id'); - $entity->setRelation('book', $parentMap[$key] ?? null); + $key = 'book:' . $entity->getRawAttribute('book_id'); + $entity->setAttribute('book', $parentMap[$key] ?? null); } if ($entity instanceof Page) { - $key = 'chapter:' . $entity->getAttribute('chapter_id'); - $entity->setRelation('chapter', $parentMap[$key] ?? null); + $key = 'chapter:' . $entity->getRawAttribute('chapter_id'); + $entity->setAttribute('chapter', $parentMap[$key] ?? null); } } } diff --git a/app/Search/SearchRunner.php b/app/Search/SearchRunner.php index 72ebe96bb..4b19aceac 100644 --- a/app/Search/SearchRunner.php +++ b/app/Search/SearchRunner.php @@ -109,17 +109,12 @@ class SearchRunner protected function getPageOfDataFromQuery(EloquentBuilder $query, int $page, int $count): Collection { $entities = $query->clone() -// ->with(array_filter($relations)) ->skip(($page - 1) * $count) ->take($count) ->get(); $hydrated = (new EntityHydrator($entities->all(), true, true))->hydrate(); - // TODO - Load in books for pages/chapters efficiently (scoped to visible) - // TODO - Load in chapters for pages efficiently (scoped to visible) - // TODO - Load in tags efficiently - return collect($hydrated); }