diff --git a/app/Http/Controllers/StatusPageController.php b/app/Http/Controllers/StatusPageController.php index 87ced74b..cd431b4c 100644 --- a/app/Http/Controllers/StatusPageController.php +++ b/app/Http/Controllers/StatusPageController.php @@ -96,7 +96,8 @@ class StatusPageController extends AbstractApiController $nextDate = $startDate->copy()->addDays($appIncidentDays)->toDateString(); } - $allIncidents = Incident::where('visible', '>=', (int) !Auth::check())->whereBetween('occurred_at', [ + $allIncidents = Incident::with('component')->with('updates.incident') + ->where('visible', '>=', (int) !Auth::check())->whereBetween('occurred_at', [ $endDate->format('Y-m-d').' 00:00:00', $startDate->format('Y-m-d').' 23:59:59', ])->orderBy('occurred_at', 'desc')->get()->groupBy(function (Incident $incident) { diff --git a/app/Presenters/ComponentGroupPresenter.php b/app/Presenters/ComponentGroupPresenter.php index 59756394..2acb112e 100644 --- a/app/Presenters/ComponentGroupPresenter.php +++ b/app/Presenters/ComponentGroupPresenter.php @@ -20,6 +20,8 @@ class ComponentGroupPresenter extends BasePresenter implements Arrayable { use TimestampsTrait; + protected $enabledComponentsLowest = false; + /** * Returns the lowest component status. * @@ -27,7 +29,7 @@ class ComponentGroupPresenter extends BasePresenter implements Arrayable */ public function lowest_status() { - if ($component = $this->wrappedObject->enabled_components_lowest()->first()) { + if ($component = $this->enabled_components_lowest()) { return AutoPresenter::decorate($component)->status; } } @@ -39,7 +41,7 @@ class ComponentGroupPresenter extends BasePresenter implements Arrayable */ public function lowest_human_status() { - if ($component = $this->wrappedObject->enabled_components_lowest()->first()) { + if ($component = $this->enabled_components_lowest()) { return AutoPresenter::decorate($component)->human_status; } } @@ -51,11 +53,25 @@ class ComponentGroupPresenter extends BasePresenter implements Arrayable */ public function lowest_status_color() { - if ($component = $this->wrappedObject->enabled_components_lowest()->first()) { + if ($component = $this->enabled_components_lowest()) { return AutoPresenter::decorate($component)->status_color; } } + /** + * Return the enabled components from the wrapped object, and cache it if need be + * + * @return bool + */ + public function enabled_components_lowest() + { + if (is_bool($this->enabledComponentsLowest)) { + $this->enabledComponentsLowest = $this->wrappedObject->enabled_components_lowest()->first(); + } + + return $this->enabledComponentsLowest; + } + /** * Determine the class for collapsed/uncollapsed groups. * diff --git a/app/Presenters/IncidentPresenter.php b/app/Presenters/IncidentPresenter.php index adab69c1..57d49525 100644 --- a/app/Presenters/IncidentPresenter.php +++ b/app/Presenters/IncidentPresenter.php @@ -29,6 +29,8 @@ class IncidentPresenter extends BasePresenter implements Arrayable */ protected $dates; + protected $latest = false; + /** * Incident icon lookup. * @@ -248,9 +250,11 @@ class IncidentPresenter extends BasePresenter implements Arrayable */ public function latest() { - if ($update = $this->wrappedObject->updates()->orderBy('created_at', 'desc')->first()) { - return $update; + if (is_bool($this->latest)) { + $this->latest = $this->wrappedObject->updates()->orderBy('created_at', 'desc')->first(); } + + return $this->latest; } /**