Skip to content

Commit

Permalink
Development: Improve git access operations performance (#9809)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonEntholzer authored and N0W0RK committed Jan 14, 2025
1 parent 3172745 commit 8a1f970
Show file tree
Hide file tree
Showing 22 changed files with 465 additions and 426 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ Optional<ProgrammingExerciseStudentParticipation> findByIdWithAllResultsAndRelat

List<ProgrammingExerciseStudentParticipation> findAllByExerciseIdAndStudentLogin(long exerciseId, String username);

default ProgrammingExerciseStudentParticipation findByExerciseIdAndStudentLoginOrThrow(long exerciseId, String username) {
return getValueElseThrow(findByExerciseIdAndStudentLogin(exerciseId, username));
@EntityGraph(type = LOAD, attributePaths = { "submissions" })
Optional<ProgrammingExerciseStudentParticipation> findWithSubmissionsByRepositoryUri(String repositoryUri);

default ProgrammingExerciseStudentParticipation findWithSubmissionsByRepositoryUriElseThrow(String repositoryUri) {
return getValueElseThrow(findWithSubmissionsByRepositoryUri(repositoryUri));
}

Optional<ProgrammingExerciseStudentParticipation> findByRepositoryUri(String repositoryUri);
Expand All @@ -88,41 +91,9 @@ default ProgrammingExerciseStudentParticipation findByRepositoryUriElseThrow(Str
return getValueElseThrow(findByRepositoryUri(repositoryUri));
}

@EntityGraph(type = LOAD, attributePaths = { "submissions" })
Optional<ProgrammingExerciseStudentParticipation> findWithSubmissionsByExerciseIdAndStudentLogin(long exerciseId, String username);

default ProgrammingExerciseStudentParticipation findWithSubmissionsByExerciseIdAndStudentLoginOrThrow(long exerciseId, String username) {
return getValueElseThrow(findWithSubmissionsByExerciseIdAndStudentLogin(exerciseId, username));
}

Optional<ProgrammingExerciseStudentParticipation> findByExerciseIdAndStudentLoginAndTestRun(long exerciseId, String username, boolean testRun);

@EntityGraph(type = LOAD, attributePaths = { "team.students" })
Optional<ProgrammingExerciseStudentParticipation> findByExerciseIdAndTeamId(long exerciseId, long teamId);

@Query("""
SELECT DISTINCT participation
FROM ProgrammingExerciseStudentParticipation participation
LEFT JOIN FETCH participation.team team
LEFT JOIN FETCH team.students
WHERE participation.exercise.id = :exerciseId
AND participation.team.shortName = :teamShortName
""")
Optional<ProgrammingExerciseStudentParticipation> findWithEagerStudentsByExerciseIdAndTeamShortName(@Param("exerciseId") long exerciseId,
@Param("teamShortName") String teamShortName);

@Query("""
SELECT DISTINCT participation
FROM ProgrammingExerciseStudentParticipation participation
LEFT JOIN FETCH participation.submissions
LEFT JOIN FETCH participation.team team
LEFT JOIN FETCH team.students
WHERE participation.exercise.id = :exerciseId
AND participation.team.shortName = :teamShortName
""")
Optional<ProgrammingExerciseStudentParticipation> findWithSubmissionsAndEagerStudentsByExerciseIdAndTeamShortName(@Param("exerciseId") long exerciseId,
@Param("teamShortName") String teamShortName);

@Query("""
SELECT DISTINCT participation
FROM ProgrammingExerciseStudentParticipation participation
Expand Down Expand Up @@ -159,17 +130,6 @@ Optional<ProgrammingExerciseStudentParticipation> findWithSubmissionsAndEagerStu
List<ProgrammingExerciseStudentParticipation> findWithSubmissionsByExerciseIdAndParticipationIds(@Param("exerciseId") long exerciseId,
@Param("participationIds") Collection<Long> participationIds);

@Query("""
SELECT participation
FROM ProgrammingExerciseStudentParticipation participation
LEFT JOIN FETCH participation.submissions
WHERE participation.exercise.id = :exerciseId
AND participation.student.login = :username
AND participation.testRun = :testRun
""")
Optional<ProgrammingExerciseStudentParticipation> findWithSubmissionsByExerciseIdAndStudentLoginAndTestRun(@Param("exerciseId") long exerciseId,
@Param("username") String username, @Param("testRun") boolean testRun);

@Query("""
SELECT participation.repositoryUri
FROM ProgrammingExerciseStudentParticipation participation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ public interface SolutionProgrammingExerciseParticipationRepository
""")
Optional<SolutionProgrammingExerciseParticipation> findByBuildPlanIdWithResults(@Param("buildPlanId") String buildPlanId);

Optional<SolutionProgrammingExerciseParticipation> findByRepositoryUri(String repositoryUri);

default SolutionProgrammingExerciseParticipation findByRepositoryUriElseThrow(String repositoryUri) {
return getValueElseThrow(findByRepositoryUri(repositoryUri));
}

@EntityGraph(type = LOAD, attributePaths = { "results", "submissions", "submissions.results" })
Optional<SolutionProgrammingExerciseParticipation> findWithEagerResultsAndSubmissionsByProgrammingExerciseId(long exerciseId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public interface TemplateProgrammingExerciseParticipationRepository
""")
Optional<TemplateProgrammingExerciseParticipation> findByBuildPlanIdWithResults(@Param("buildPlanId") String buildPlanId);

@EntityGraph(type = LOAD, attributePaths = { "results", "submissions" })
Optional<TemplateProgrammingExerciseParticipation> findWithEagerResultsAndSubmissionsByProgrammingExerciseId(long exerciseId);
@EntityGraph(type = LOAD, attributePaths = { "submissions" })
Optional<TemplateProgrammingExerciseParticipation> findWithSubmissionsByRepositoryUri(String repositoryUri);

default TemplateProgrammingExerciseParticipation findWithEagerResultsAndSubmissionsByProgrammingExerciseIdElseThrow(long exerciseId) {
return getValueElseThrow(findWithEagerResultsAndSubmissionsByProgrammingExerciseId(exerciseId));
default TemplateProgrammingExerciseParticipation findWithSubmissionsByRepositoryUriElseThrow(String repositoryUri) {
return getValueElseThrow(findWithSubmissionsByRepositoryUri(repositoryUri));
}

Optional<TemplateProgrammingExerciseParticipation> findByRepositoryUri(String repositoryUri);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,36 @@
public interface VcsAccessLogRepository extends ArtemisJpaRepository<VcsAccessLog, Long> {

/**
* Find the access log entry which does not have any commit hash yet
* Retrieves the most recent {@link VcsAccessLog} for a given participation ID.
*
* @param participationId The id of the participation the repository belongs to
* @return a log entry belonging to the participationId, which has no commit hash
* @param participationId the ID of the participation to filter by.
* @return an {@link Optional} containing the newest {@link VcsAccessLog}, or empty if none exists.
*/
@Query("""
SELECT vcsAccessLog
FROM VcsAccessLog vcsAccessLog
WHERE vcsAccessLog.participation.id = :participationId
ORDER BY vcsAccessLog.timestamp DESC
LIMIT 1
FROM VcsAccessLog vcsAccessLog
WHERE vcsAccessLog.participation.id = :participationId
ORDER BY vcsAccessLog.id DESC
LIMIT 1
""")
Optional<VcsAccessLog> findNewestByParticipationId(@Param("participationId") long participationId);

/**
* Retrieves the most recent {@link VcsAccessLog} for a specific repository URI of a participation.
*
* @param repositoryUri the URI of the participation to filter by.
* @return an Optional containing the newest {@link VcsAccessLog} of the participation, or empty if none exists.
*/
@Query("""
SELECT vcsAccessLog
FROM VcsAccessLog vcsAccessLog
LEFT JOIN TREAT (vcsAccessLog.participation AS ProgrammingExerciseStudentParticipation) participation
WHERE participation.repositoryUri = :repositoryUri
ORDER BY vcsAccessLog.id DESC
LIMIT 1
""")
Optional<VcsAccessLog> findNewestByRepositoryUri(@Param("repositoryUri") String repositoryUri);

/**
* Retrieves a list of {@link VcsAccessLog} entities associated with the specified participation ID.
* The results are ordered by the log ID in ascending order.
Expand Down
Loading

0 comments on commit 8a1f970

Please sign in to comment.