From bf6296ac7d2c8a144bd0c37a72be5d0d3af4c645 Mon Sep 17 00:00:00 2001 From: Lucas Welscher Date: Wed, 13 Nov 2024 11:42:37 +0100 Subject: [PATCH] `Development`: Speedup loading active courses --- .../artemis/core/repository/CourseRepository.java | 13 ++++++++++++- .../cit/aet/artemis/core/web/CourseResource.java | 7 ++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/tum/cit/aet/artemis/core/repository/CourseRepository.java b/src/main/java/de/tum/cit/aet/artemis/core/repository/CourseRepository.java index 8d9aa0c09df5..b08bc1ca44d4 100644 --- a/src/main/java/de/tum/cit/aet/artemis/core/repository/CourseRepository.java +++ b/src/main/java/de/tum/cit/aet/artemis/core/repository/CourseRepository.java @@ -580,5 +580,16 @@ Set findInactiveCoursesForUserRolesWithNonNullSemester(@Par OR c.instructorGroupName IN :userGroups OR :isAdmin = TRUE """) - List findCoursesForAtLeastTutorWithGroups(@Param("userGroups") Set userGroups, @Param("isAdmin") boolean isAdmin); + List findAllCoursesForAtLeastTutorWithGroups(@Param("userGroups") Set userGroups, @Param("isAdmin") boolean isAdmin); + + @Query(""" + SELECT c + FROM Course c + WHERE (c.teachingAssistantGroupName IN :userGroups + OR c.editorGroupName IN :userGroups + OR c.instructorGroupName IN :userGroups + OR :isAdmin = TRUE) + AND (c.endDate >= :now OR c.endDate IS NULL) + """) + List findActiveCoursesForAtLeastTutorWithGroups(@Param("userGroups") Set userGroups, @Param("isAdmin") boolean isAdmin, @Param("now") ZonedDateTime now); } diff --git a/src/main/java/de/tum/cit/aet/artemis/core/web/CourseResource.java b/src/main/java/de/tum/cit/aet/artemis/core/web/CourseResource.java index ba364d0c4fb5..2a0a19d80b5e 100644 --- a/src/main/java/de/tum/cit/aet/artemis/core/web/CourseResource.java +++ b/src/main/java/de/tum/cit/aet/artemis/core/web/CourseResource.java @@ -445,13 +445,14 @@ public ResponseEntity> getCourses(@RequestParam(defaultValue = "fal } private List getCoursesForTutors(User user, boolean onlyActive) { - List userCourses = courseRepository.findCoursesForAtLeastTutorWithGroups(user.getGroups(), authCheckService.isAdmin(user)); if (onlyActive) { // only include courses that have NOT been finished final var now = ZonedDateTime.now(); - userCourses = userCourses.stream().filter(course -> course.getEndDate() == null || course.getEndDate().isAfter(now)).toList(); + return courseRepository.findActiveCoursesForAtLeastTutorWithGroups(user.getGroups(), authCheckService.isAdmin(user), now); + } + else { + return courseRepository.findAllCoursesForAtLeastTutorWithGroups(user.getGroups(), authCheckService.isAdmin(user)); } - return userCourses; } /**