Merge pull request #3357 from AdrienPoupa/duplicate-queries

Improve database performance by removing duplicated queries and using eager loading
This commit is contained in:
James Brooks
2019-01-07 13:21:25 +00:00
committed by GitHub
8 changed files with 110 additions and 15 deletions

View File

@@ -73,7 +73,7 @@ class ComponentController extends Controller
*/
public function showComponents()
{
$components = Component::orderBy('order')->orderBy('created_at')->get();
$components = Component::with('group')->orderBy('order')->orderBy('created_at')->get();
$this->subMenu['components']['active'] = true;

View File

@@ -75,7 +75,7 @@ class IncidentController extends Controller
*/
public function showIncidents()
{
$incidents = Incident::orderBy('created_at', 'desc')->get();
$incidents = Incident::with('user')->orderBy('created_at', 'desc')->get();
return View::make('dashboard.incidents.index')
->withPageTitle(trans('dashboard.incidents.incidents').' - '.trans('dashboard.dashboard'))

View File

@@ -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) {