Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin slows down course overview --> cache needed #455

Closed
schuettloeffel-elsa opened this issue Nov 2, 2023 · 3 comments
Closed

Plugin slows down course overview --> cache needed #455

schuettloeffel-elsa opened this issue Nov 2, 2023 · 3 comments
Assignees
Milestone

Comments

@schuettloeffel-elsa
Copy link
Contributor

I did some research on loading times for the meeting plugin and found out that the calculation for getIconNavigation() is quite slow. Main Problem is the fetching of all meetings for a specific course from the database in MeetingCourse::findActiveByCourseId().

First of all, the query is pretty slow since it has to sort a an unindexed column --> maybe an index for vc_meetings.name should be added and the ORDER BY m.name + 0, m.name should be changed to ORDER BY m.name for a faster sorting.

Second, even if the query is optimised, it takes ~0.015 seconds to execute on our systems (the table is quite large with 34k entries). Having e.g. 8 different courses in the course overview adds up to 100ms waiting time just for these queries, and most students have way more than 8 courses in the list. What to do? Maybe implement a cache:

diff --git a/MeetingPlugin.php b/MeetingPlugin.php
index 4b3d432..459bb56 100644
--- a/MeetingPlugin.php
+++ b/MeetingPlugin.php
@@ -167,10 +167,19 @@ class MeetingPlugin extends StudIPPlugin implements PortalPlugin, StandardPlugin
         /** @var Seminar_Perm $perm */
         $perm = $GLOBALS['perm'];
 
+        $cache = StudipCacheFactory::getCache();
         if ($perm->have_studip_perm('tutor', $courseId)) {
-            $courses = MeetingCourse::findByCourseId($courseId);
+            $courses = unserialize($cache->read('plugins/MeetingPlugin/MeetingCourse/' . $courseId));
+            if (empty($courses)) {
+                $courses = MeetingCourse::findByCourseId($courseId);
+                $cache->write('plugins/MeetingPlugin/MeetingCourse/' . $courseId, serialize($courses), 3600);
+            }
         } else {
-            $courses = MeetingCourse::findActiveByCourseId($courseId);
+            $courses = unserialize($cache->read('plugins/MeetingPlugin/MeetingCourse/active/' . $courseId));
+            if (empty($courses)) {
+                $courses = MeetingCourse::findActiveByCourseId($courseId);
+                $cache->write('plugins/MeetingPlugin/MeetingCourse/active/' . $courseId, serialize($courses), 3600);
+            }
         }

--> having that cache improved the response time for the course overview by 100ms (from 230ms to 130ms) on our test systems!

@ferishili ferishili added this to the > 2.81 milestone Apr 30, 2024
@ferishili ferishili self-assigned this Apr 30, 2024
@ferishili
Copy link
Collaborator

Hi @schuettloeffel-elsa
Thanks for your contribution.
Just for your info: You could have made a PR for this enhancement.
The part for optimizing the query for sorting, I would prefer not to change it for now.

Best Regards

@schuettloeffel-elsa
Copy link
Contributor Author

Allright, next time :)

@ferishili
Copy link
Collaborator

In addition to the cache, the index is also added to that table, so there would solve the performance issue very well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants