aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorThomas Hackl <hackl@data-quest.de>2025-04-01 13:59:42 +0000
committerThomas Hackl <hackl@data-quest.de>2025-04-01 13:59:42 +0000
commit6416abc1e4447a57eb8d9d72a1e8eb908709a4dc (patch)
tree99a7f401750cc1b7a8f3173aae16dfcfbca5f2a8 /lib
parent3c896ae484b71676d5f5e5c4c5984f608a54c51b (diff)
Resolve "Viele DB Anfragen an semester_data und seminar_inst auf jeder Seite"
Closes #5418 and #5442 Merge request studip/studip!4080
Diffstat (limited to 'lib')
-rw-r--r--lib/classes/ResponsiveHelper.php118
1 files changed, 78 insertions, 40 deletions
diff --git a/lib/classes/ResponsiveHelper.php b/lib/classes/ResponsiveHelper.php
index d4d0651..e8e6231 100644
--- a/lib/classes/ResponsiveHelper.php
+++ b/lib/classes/ResponsiveHelper.php
@@ -191,61 +191,99 @@ class ResponsiveHelper
*/
protected static function getMyCoursesNavigation($activated): array
{
- if (!$GLOBALS['perm']->have_perm('admin')) {
- $sem_data = Semester::getAllAsArray();
+ $cache = \Studip\Cache\Factory::getCache();
+ $cached = $cache->read("my_courses_of_" . User::findCurrent()->id);
- $currentIndex = -1;
+ if (!$cached) {
- foreach ($sem_data as $index => $semester) {
- if (!empty($semester['current'])) {
- $currentIndex = $index;
- break;
+ if (!$GLOBALS['perm']->have_perm('admin')) {
+
+ $sem_data = Semester::getAllAsArray();
+
+ $currentIndex = -1;
+
+ foreach ($sem_data as $index => $semester) {
+ if (!empty($semester['current'])) {
+ $currentIndex = $index;
+ break;
+ }
}
+
+ $params = [
+ 'deputies_enabled' => Config::get()->DEPUTIES_ENABLE
+ ];
+
+ $courses = MyRealmModel::getCourses($currentIndex, $currentIndex, $params);
+
+ } else {
+ $courses = [];
}
- $params = [
- 'deputies_enabled' => Config::get()->DEPUTIES_ENABLE
- ];
+ $items = [];
+ foreach ($courses as $course) {
+ $avatar = CourseAvatar::getAvatar($course->id);
+ $hasAvatar = $avatar->is_customized();
+ $icon = $hasAvatar
+ ? $avatar->getURL(Avatar::SMALL)
+ : Icon::create('seminar', Icon::ROLE_INFO_ALT)->asImagePath();
+
+ $items['browse/my_courses/' . $course->id] = [
+ 'icon' => $icon,
+ 'avatar' => $hasAvatar,
+ 'title' => $course->getFullName(),
+ 'url' => URLHelper::getURL('dispatch.php/course/details', ['cid' => $course->id]),
+ 'parent' => 'browse/my_courses',
+ 'path' => 'browse/my_courses/' . $course->id,
+ 'visible' => true,
+ 'active' => Context::getId() === $course->id,
+ 'children' => self::getRangeNavigation(
+ $course,
+ 'browse/my_courses/' . $course->id,
+ $activated
+ ),
+ ];
+
+ }
+
+ $cache->write("my_courses_of_" . User::findCurrent()->id, json_encode($items));
- $courses = MyRealmModel::getCourses($currentIndex, $currentIndex, $params);
} else {
- $courses = [];
- }
- // Add current course to list.
- if (Context::get()) {
- $courses[] = Context::get();
+ $items = json_decode($cached, true);
+
}
+ // Add current course/institute to list if not already present. This should not be cached.
+ if (Context::get()) {
- if (Context::isInstitute()) {
- $avatarClass = InstituteAvatar::class;
- $url = 'dispatch.php/institute/overview';
- $standardIcon = Icon::create('institute', Icon::ROLE_INFO_ALT)->asImagePath();
- } else {
- $avatarClass = CourseAvatar::class;
- $url = 'dispatch.php/course/details';
- $standardIcon = Icon::create('seminar', Icon::ROLE_INFO_ALT)->asImagePath();
- }
+ if (Context::isInstitute()) {
+ $avatarClass = InstituteAvatar::class;
+ $url = 'dispatch.php/institute/overview';
+ $standardIcon = Icon::create('institute', Icon::ROLE_INFO_ALT)->asImagePath();
+ } else {
+ $avatarClass = CourseAvatar::class;
+ $url = 'dispatch.php/course/details';
+ $standardIcon = Icon::create('seminar', Icon::ROLE_INFO_ALT)->asImagePath();
+ }
- $items = [];
- foreach ($courses as $course) {
$avatar = $avatarClass::getAvatar($course->id);
$hasAvatar = $avatar->is_customized();
- $icon = $hasAvatar ? $avatar->getURL(Avatar::SMALL) : $standardIcon;
-
- $items['browse/my_courses/' . $course->id] = [
- 'icon' => $icon,
- 'avatar' => $hasAvatar,
- 'title' => $course->getFullName(),
- 'url' => URLHelper::getURL($url, ['cid' => $course->id]),
- 'parent' => 'browse/my_courses',
- 'path' => 'browse/my_courses/' . $course->id,
- 'visible' => true,
- 'active' => Context::getId() === $course->id,
+ $icon = $hasAvatar
+ ? $avatar->getURL(Avatar::SMALL)
+ : $standardIcon;
+
+ $items['browse/my_courses/' . Context::getId()] = [
+ 'icon' => $icon,
+ 'avatar' => $hasAvatar,
+ 'title' => Context::get()->getFullName(),
+ 'url' => URLHelper::getURL($url, ['cid' => Context::getId()]),
+ 'parent' => 'browse/my_courses',
+ 'path' => 'browse/my_courses/' . Context::getId(),
+ 'visible' => true,
+ 'active' => true,
'children' => self::getRangeNavigation(
- $course,
- 'browse/my_courses/' . $course->id,
+ Context::get(),
+ 'browse/my_courses/' . Context::getId(),
$activated
),
];