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

Adaptive learning: Fix query performance when retrieving exercise information for mastery calculation #8871

Merged
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 @@ -16,6 +16,7 @@
import org.springframework.stereotype.Repository;

import de.tum.in.www1.artemis.domain.Course;
import de.tum.in.www1.artemis.domain.User;
import de.tum.in.www1.artemis.domain.competency.Competency;
import de.tum.in.www1.artemis.repository.base.ArtemisJpaRepository;
import de.tum.in.www1.artemis.web.rest.dto.metrics.CompetencyExerciseMasteryCalculationDTO;
Expand Down Expand Up @@ -66,6 +67,7 @@ public interface CompetencyRepository extends ArtemisJpaRepository<Competency, L
* The complex grouping by is necessary for postgres
*
* @param competencyId the id of the competency for which to fetch the exercise information
* @param user the user for which to fetch the exercise information
* @return the exercise information for the calculation of the mastery in the competency
*/
@Query("""
Expand All @@ -80,15 +82,15 @@ CASE WHEN TYPE(ex) = ProgrammingExercise THEN TRUE ELSE FALSE END,
)
FROM Competency c
LEFT JOIN c.exercises ex
LEFT JOIN ex.studentParticipations sp
LEFT JOIN ex.studentParticipations sp ON sp.student = :user OR :user MEMBER OF sp.team.students
LEFT JOIN sp.submissions s
LEFT JOIN StudentScore sS ON sS.exercise = ex
LEFT JOIN TeamScore tS ON tS.exercise = ex
LEFT JOIN StudentScore sS ON sS.exercise = ex AND sS.user = :user
LEFT JOIN TeamScore tS ON tS.exercise = ex AND :user MEMBER OF tS.team.students
WHERE c.id = :competencyId
AND ex IS NOT NULL
GROUP BY ex.maxPoints, ex.difficulty, TYPE(ex), sS.lastScore, tS.lastScore, sS.lastPoints, tS.lastPoints, sS.lastModifiedDate, tS.lastModifiedDate
""")
Set<CompetencyExerciseMasteryCalculationDTO> findAllExerciseInfoByCompetencyId(@Param("competencyId") long competencyId);
Set<CompetencyExerciseMasteryCalculationDTO> findAllExerciseInfoByCompetencyId(@Param("competencyId") long competencyId, @Param("user") User user);

@Query("""
SELECT c
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public CompetencyProgress updateCompetencyProgress(Long competencyId, User user)

Competency competency = optionalCompetency.get();
Set<LectureUnit> lectureUnits = competency.getLectureUnits().stream().filter(lectureUnit -> !(lectureUnit instanceof ExerciseUnit)).collect(Collectors.toSet());
Set<CompetencyExerciseMasteryCalculationDTO> exerciseInfos = competencyRepository.findAllExerciseInfoByCompetencyId(competencyId);
Set<CompetencyExerciseMasteryCalculationDTO> exerciseInfos = competencyRepository.findAllExerciseInfoByCompetencyId(competencyId, user);
int numberOfCompletedLectureUnits = lectureUnitCompletionRepository
.countByLectureUnitIds(competency.getLectureUnits().stream().map(LectureUnit::getId).collect(Collectors.toSet()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ public void createStudentScore(Exercise exercise, User user, Result result) {
studentScore.setLastResult(result);
studentScore.setLastScore(result.getScore());
studentScore.setLastPoints(exercise.getMaxPoints() * result.getScore() / 100);
if (Boolean.TRUE.equals(result.isRated())) {
studentScore.setLastRatedResult(result);
studentScore.setLastRatedScore(result.getScore());
studentScore.setLastRatedPoints(exercise.getMaxPoints() * result.getScore() / 100);
}
krusche marked this conversation as resolved.
Show resolved Hide resolved

studentScoreRepository.save(studentScore);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ void getCompetencyStudentProgressShouldReturnProgress() throws Exception {
User student1 = userRepository.findOneByLogin(TEST_PREFIX + "student1").orElseThrow();
lectureUnitService.setLectureUnitCompletion(textUnitRepository.findById(idOfTextUnitOfLectureOne).orElseThrow(), student1, true);

createTextExerciseParticipationSubmissionAndResult(textExercise, student1, 10.0, 0.0, 90, true); // will be ignored in favor of last submission from team
createTextExerciseParticipationSubmissionAndResult(textExercise, student1, 10.0, 0.0, 90, true);
createTextExerciseParticipationSubmissionAndResult(textExercise, student1, 10.0, 0.0, 85, false);

await().until(() -> participantScoreScheduleService.isIdle());
Expand Down
Loading