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

Development: Speedup loading of active courses #9768

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading