From 7d95f4f6034cc31455d9f03557acd5fbb106a87b Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 5 Jun 2024 17:38:26 -0700 Subject: [PATCH] Eliminate array_merge when calculating examAttempts. Part 1 of a performance overhaul. --- app/Http/Controllers/MgtController.php | 26 ++++++++++++-------------- app/Http/Controllers/MyController.php | 26 ++++++++++++-------------- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/app/Http/Controllers/MgtController.php b/app/Http/Controllers/MgtController.php index 5ec3b5c..af24692 100644 --- a/app/Http/Controllers/MgtController.php +++ b/app/Http/Controllers/MgtController.php @@ -141,28 +141,26 @@ public function getController(Request $request, $cid = null) $c1AssignmentDate = $moodle->getUserEnrolmentTimestamp($uid, config('exams.C1.enrolId')); $examAttempts = [ - 'Basic ATC/S1 Exam' => array_merge([ + 'Basic ATC/S1 Exam' => [ 'examInfo' => config('exams.BASIC'), 'assignDate' => $basicAssignmentDate ? - Carbon::createFromTimestampUTC($basicAssignmentDate)->format('Y-m-d H:i') : false - ], ['attempts' => $moodle->getQuizAttempts(config('exams.BASIC.id'), null, $uid)]), - 'S2 Rating (TWR) Controller Exam' => array_merge([ + Carbon::createFromTimestampUTC($basicAssignmentDate)->format('Y-m-d H:i') : false, + 'attempts' => $moodle->getQuizAttempts(config('exams.BASIC.id'), null, $uid)], + 'S2 Rating (TWR) Controller Exam' => [ 'examInfo' => config('exams.S2'), 'assignDate' => $s2AssignmentDate ? - Carbon::createFromTimestampUTC($s2AssignmentDate)->format('Y-m-d H:i') : false - ], ['attempts' => $moodle->getQuizAttempts(config('exams.S2.id'), null, $uid)]), - 'S3 Rating (DEP/APP) Controller Exam' => array_merge([ + Carbon::createFromTimestampUTC($s2AssignmentDate)->format('Y-m-d H:i') : false, + 'attempts' => $moodle->getQuizAttempts(config('exams.S2.id'), null, $uid)], + 'S3 Rating (DEP/APP) Controller Exam' => [ 'examInfo' => config('exams.S3'), 'assignDate' => $s3AssignmentDate ? - Carbon::createFromTimestampUTC($s3AssignmentDate)->format('Y-m-d H:i') : false - ], - ['attempts' => $moodle->getQuizAttempts(config('exams.S3.id'), null, $uid)]), - 'C1 Rating (CTR) Controller Exam' => array_merge([ + Carbon::createFromTimestampUTC($s3AssignmentDate)->format('Y-m-d H:i') : false, + 'attempts' => $moodle->getQuizAttempts(config('exams.S3.id'), null, $uid)], + 'C1 Rating (CTR) Controller Exam' => [ 'examInfo' => config('exams.C1'), 'assignDate' => $c1AssignmentDate ? - Carbon::createFromTimestampUTC($c1AssignmentDate)->format('Y-m-d H:i') : false - ], - ['attempts' => $moodle->getQuizAttempts(config('exams.C1.id'), null, $uid)]), + Carbon::createFromTimestampUTC($c1AssignmentDate)->format('Y-m-d H:i') : false, + 'attempts' => $moodle->getQuizAttempts(config('exams.C1.id'), null, $uid)], ]; $assignedRoles = RoleHelperV2::assignedRoles($cid); diff --git a/app/Http/Controllers/MyController.php b/app/Http/Controllers/MyController.php index d0dae78..268e777 100644 --- a/app/Http/Controllers/MyController.php +++ b/app/Http/Controllers/MyController.php @@ -73,28 +73,26 @@ public function getProfile(Request $request) { config('exams.C1.enrolId')); $examAttempts = [ - 'Basic ATC/S1 Exam' => array_merge([ + 'Basic ATC/S1 Exam' => [ 'examInfo' => config('exams.BASIC'), 'assignDate' => $basicAssignmentDate ? - Carbon::createFromTimestampUTC($basicAssignmentDate)->format('Y-m-d H:i') : false - ], ['attempts' => $moodle->getQuizAttempts(config('exams.BASIC.id'), null, $uid)]), - 'S2 Rating (TWR) Controller Exam' => array_merge([ + Carbon::createFromTimestampUTC($basicAssignmentDate)->format('Y-m-d H:i') : false, + 'attempts' => $moodle->getQuizAttempts(config('exams.BASIC.id'), null, $uid)], + 'S2 Rating (TWR) Controller Exam' => [ 'examInfo' => config('exams.S2'), 'assignDate' => $s2AssignmentDate ? - Carbon::createFromTimestampUTC($s2AssignmentDate)->format('Y-m-d H:i') : false - ], ['attempts' => $moodle->getQuizAttempts(config('exams.S2.id'), null, $uid)]), - 'S3 Rating (DEP/APP) Controller Exam' => array_merge([ + Carbon::createFromTimestampUTC($s2AssignmentDate)->format('Y-m-d H:i') : false, + 'attempts' => $moodle->getQuizAttempts(config('exams.S2.id'), null, $uid)], + 'S3 Rating (DEP/APP) Controller Exam' => [ 'examInfo' => config('exams.S3'), 'assignDate' => $s3AssignmentDate ? - Carbon::createFromTimestampUTC($s3AssignmentDate)->format('Y-m-d H:i') : false - ], - ['attempts' => $moodle->getQuizAttempts(config('exams.S3.id'), null, $uid)]), - 'C1 Rating (CTR) Controller Exam' => array_merge([ + Carbon::createFromTimestampUTC($s3AssignmentDate)->format('Y-m-d H:i') : false, + 'attempts' => $moodle->getQuizAttempts(config('exams.S3.id'), null, $uid)], + 'C1 Rating (CTR) Controller Exam' => [ 'examInfo' => config('exams.C1'), 'assignDate' => $c1AssignmentDate ? - Carbon::createFromTimestampUTC($c1AssignmentDate)->format('Y-m-d H:i') : false - ], - ['attempts' => $moodle->getQuizAttempts(config('exams.C1.id'), null, $uid)]), + Carbon::createFromTimestampUTC($c1AssignmentDate)->format('Y-m-d H:i') : false, + 'attempts' => $moodle->getQuizAttempts(config('exams.C1.id'), null, $uid)], ]; return view('my.profile',