Improve database performance by removing duplicated queries
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user