Skip to content

Commit

Permalink
Development: Speedup loading active courses
Browse files Browse the repository at this point in the history
  • Loading branch information
Strohgelaender committed Nov 13, 2024
1 parent 054476c commit bf6296a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -580,5 +580,16 @@ Set<CourseForArchiveDTO> findInactiveCoursesForUserRolesWithNonNullSemester(@Par
OR c.instructorGroupName IN :userGroups
OR :isAdmin = TRUE
""")
List<Course> findCoursesForAtLeastTutorWithGroups(@Param("userGroups") Set<String> userGroups, @Param("isAdmin") boolean isAdmin);
List<Course> findAllCoursesForAtLeastTutorWithGroups(@Param("userGroups") Set<String> 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<Course> findActiveCoursesForAtLeastTutorWithGroups(@Param("userGroups") Set<String> userGroups, @Param("isAdmin") boolean isAdmin, @Param("now") ZonedDateTime now);
}
Original file line number Diff line number Diff line change
Expand Up @@ -445,13 +445,14 @@ public ResponseEntity<List<Course>> getCourses(@RequestParam(defaultValue = "fal
}

private List<Course> getCoursesForTutors(User user, boolean onlyActive) {
List<Course> 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;
}

/**
Expand Down

0 comments on commit bf6296a

Please sign in to comment.