Skip to content

Commit

Permalink
Development: Optimize exam query
Browse files Browse the repository at this point in the history
  • Loading branch information
krusche committed Dec 15, 2024
1 parent c4bc5a8 commit 1435bfe
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ public Course findOneWithExercisesAndLecturesAndExamsAndCompetenciesAndTutorialG
course.setExercises(exerciseRepository.findByCourseIdWithCategories(course.getId()));
course.setExercises(exerciseService.filterExercisesForCourse(course, user));
exerciseService.loadExerciseDetailsIfNecessary(course, user);
course.setExams(examRepository.findByCourseIdsForUser(Set.of(course.getId()), user.getId(), user.getGroups(), ZonedDateTime.now()));
course.setExams(examRepository.findByCourseIdForUser(course.getId(), user.getId(), user.getGroups(), ZonedDateTime.now()));
// TODO: in the future, we only want to know if lectures exist, the actual lectures will be loaded when the user navigates into the lecture
course.setLectures(lectureService.filterVisibleLecturesWithActiveAttachments(course, course.getLectures(), user));
// NOTE: in this call we only want to know if competencies exist in the course, we will load them when the user navigates into them
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,30 @@ public interface ExamRepository extends ArtemisJpaRepository<Exam, Long> {
List<Exam> findByCourseIdWithExerciseGroupsAndExercises(@Param("courseId") long courseId);

/**
* Find all exams for multiple courses that are already visible to the user (either registered, at least tutor or the exam is a test exam)
* Find all exams for a given course that are already visible to the user (either registered, at least tutor or the exam is a test exam)
*
* @param courseIds set of courseIds that the exams should be retrieved
* @param courseId the course for which the exams should be retrieved
* @param userId the id of the user requesting the exams
* @param groupNames the groups of the user requesting the exams
* @param now the current date, typically ZonedDateTime.now()
* @return a set of all visible exams for the user in the provided courses
*/
@Query("""
SELECT e
SELECT DISTINCT e
FROM Exam e
LEFT JOIN e.examUsers registeredUsers
WHERE e.course.id IN :courseIds
LEFT JOIN e.examUsers eu
LEFT JOIN e.course c
WHERE c.id = :courseId
AND e.visibleDate <= :now
AND (
registeredUsers.user.id = :userId
OR e.course.teachingAssistantGroupName IN :groupNames
OR e.course.editorGroupName IN :groupNames
OR e.course.instructorGroupName IN :groupNames
eu.user.id = :userId
OR c.teachingAssistantGroupName IN :groupNames
OR c.editorGroupName IN :groupNames
OR c.instructorGroupName IN :groupNames
OR e.testExam = TRUE
)
""")
Set<Exam> findByCourseIdsForUser(@Param("courseIds") Set<Long> courseIds, @Param("userId") long userId, @Param("groupNames") Set<String> groupNames,
@Param("now") ZonedDateTime now);
Set<Exam> findByCourseIdForUser(@Param("courseId") Long courseId, @Param("userId") long userId, @Param("groupNames") Set<String> groupNames, @Param("now") ZonedDateTime now);

@Query("""
SELECT new de.tum.cit.aet.artemis.core.dto.CourseContentCount(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public void handleEvent(IrisExerciseChatSessionService service) {

}

@Test()
@Test
@WithMockUser(username = TEST_PREFIX + "student1", roles = "USER")
void testShouldNotFireProgressStalledEventWithEventDisabled() {
// Find settings for the current exercise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void testGetAeolusTemplateFile(String templateKey, Integer expectedScriptActions
assertWindfileIsCorrect(windfile, expectedScriptActions);
}

@Test()
@Test
void testInvalidWindfileDeserialization() {
try {
String invalidWindfile = """
Expand All @@ -82,7 +82,7 @@ void testInvalidWindfileDeserialization() {
}
}

@Test()
@Test
void testValidWindfileDeserializationWithClass() throws JsonProcessingException {
String validWindfile = """
{
Expand Down Expand Up @@ -117,7 +117,7 @@ void testValidWindfileDeserializationWithClass() throws JsonProcessingException
assertThat(windfile.getActions().getFirst()).isInstanceOf(ScriptAction.class);
}

@Test()
@Test
void testValidWindfileWithInvalidAction() {
// NOTE: the misspellings are intended
String invalidWindfile = """
Expand Down

0 comments on commit 1435bfe

Please sign in to comment.