-
Notifications
You must be signed in to change notification settings - Fork 301
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
: Remove eager relationship between team and students
#7829
Conversation
There hasn't been any activity on this pull request recently. Therefore, this pull request has been automatically marked as stale and will be closed if no further activity occurs within seven days. Thank you for your contributions. |
WalkthroughThe overarching modification in the Artemis application focuses on optimizing data retrieval for team-related entities. This is achieved by shifting from eager to lazy fetching in the Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 7
Configuration used: CodeRabbit UI
Files selected for processing (24)
- src/main/java/de/tum/in/www1/artemis/domain/Team.java (1 hunks)
- src/main/java/de/tum/in/www1/artemis/repository/ParticipationRepository.java (1 hunks)
- src/main/java/de/tum/in/www1/artemis/repository/ProgrammingExerciseStudentParticipationRepository.java (1 hunks)
- src/main/java/de/tum/in/www1/artemis/repository/ProgrammingSubmissionRepository.java (1 hunks)
- src/main/java/de/tum/in/www1/artemis/repository/StudentParticipationRepository.java (1 hunks)
- src/main/java/de/tum/in/www1/artemis/repository/TeamRepository.java (6 hunks)
- src/main/java/de/tum/in/www1/artemis/repository/TeamScoreRepository.java (1 hunks)
- src/main/java/de/tum/in/www1/artemis/service/AuthorizationCheckService.java (3 hunks)
- src/main/java/de/tum/in/www1/artemis/service/ComplaintService.java (2 hunks)
- src/main/java/de/tum/in/www1/artemis/service/ParticipantScoreService.java (1 hunks)
- src/main/java/de/tum/in/www1/artemis/service/ParticipationAuthorizationCheckService.java (3 hunks)
- src/main/java/de/tum/in/www1/artemis/service/ParticipationService.java (1 hunks)
- src/main/java/de/tum/in/www1/artemis/service/TeamService.java (1 hunks)
- src/main/java/de/tum/in/www1/artemis/service/programming/ProgrammingMessagingService.java (3 hunks)
- src/main/java/de/tum/in/www1/artemis/service/programming/ProgrammingSubmissionService.java (2 hunks)
- src/main/java/de/tum/in/www1/artemis/service/scheduled/ParticipantScoreScheduleService.java (1 hunks)
- src/main/java/de/tum/in/www1/artemis/service/team/TeamImportStrategy.java (2 hunks)
- src/main/java/de/tum/in/www1/artemis/web/rest/ComplaintResponseResource.java (3 hunks)
- src/main/java/de/tum/in/www1/artemis/web/rest/ParticipationResource.java (2 hunks)
- src/main/java/de/tum/in/www1/artemis/web/rest/TeamResource.java (4 hunks)
- src/main/java/de/tum/in/www1/artemis/web/rest/open/PublicProgrammingSubmissionResource.java (1 hunks)
- src/main/java/de/tum/in/www1/artemis/web/websocket/team/TeamWebsocketService.java (5 hunks)
- src/test/java/de/tum/in/www1/artemis/DatabaseQueryCountTest.java (1 hunks)
- src/test/java/de/tum/in/www1/artemis/exercise/modelingexercise/compass/umlmodel/AbstractUMLDiagramTest.java (1 hunks)
Additional comments: 27
src/main/java/de/tum/in/www1/artemis/service/team/TeamImportStrategy.java (1)
- 5-6: The import of
org.hibernate.Hibernate
is necessary for theHibernate.isInitialized
method used in thecloneTeamsIntoDestinationExercise
method.src/main/java/de/tum/in/www1/artemis/repository/TeamScoreRepository.java (1)
- 48-52: The new method
getAchievedPointsOfTeamsWithStudents
correctly uses aLEFT JOIN FETCH
to eagerly fetch the students of the team, which should optimize database interactions.src/main/java/de/tum/in/www1/artemis/web/websocket/team/TeamWebsocketService.java (2)
7-7: The import of
org.hibernate.Hibernate
is necessary for theHibernate.isInitialized
method used in thesendTeamAssignmentUpdate
method.29-35: The addition of the
TeamRepository
field and its inclusion in the constructor are necessary for the lazy loading logic in thesendTeamAssignmentUpdate
method.src/main/java/de/tum/in/www1/artemis/domain/Team.java (1)
- 45-45: The change from
EAGER
toLAZY
fetching for thestudents
collection in theTeam
class aligns with the PR objectives to optimize database interactions.src/main/java/de/tum/in/www1/artemis/repository/ProgrammingSubmissionRepository.java (1)
- 37-53: The new JPQL query method
findByParticipationIdAndCommitHashOrderByIdDescWithFeedbacksAndTeamStudents
and the default methodfindFirstByParticipationIdAndCommitHashOrderByIdDescWithFeedbacksAndTeamStudents
are designed to optimize the retrieval ofProgrammingSubmission
entities with their associated data.src/main/java/de/tum/in/www1/artemis/repository/ParticipationRepository.java (1)
- 71-79: The methods
findWithEagerSubmissionsByIdWithTeamStudents
andfindWithEagerSubmissionsByIdWithTeamStudentsElseThrow
have been updated to include eager fetching of the team and its students, which aligns with the PR objectives to optimize database interactions.src/main/java/de/tum/in/www1/artemis/service/ParticipationAuthorizationCheckService.java (2)
9-12: The import modifications are necessary for the new logic related to team and student fetching in the
ParticipationAuthorizationCheckService
.27-35: The addition of the
TeamRepository
field and its inclusion in the constructor are necessary for the lazy loading logic in thecanAccessParticipation
method.src/main/java/de/tum/in/www1/artemis/repository/TeamRepository.java (4)
3-4: The import of
EntityGraphType.LOAD
is necessary for the@EntityGraph
annotation used in theTeamRepository
.29-29: The
@EntityGraph
annotation on thefindAllByExerciseId
method is used to eagerly fetch the students of the team, which should optimize database interactions.43-43: The simplification of the
getNumberOfTeamsForExercise
method query is a performance improvement and makes the query more readable.64-76: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [68-79]
The replacement of
findOneWithEagerStudents
withfindWithStudentsById
and the addition offindWithStudentsByIdElseThrow
are in line with the PR objectives to optimize database interactions.src/main/java/de/tum/in/www1/artemis/service/TeamService.java (1)
- 86-86: The logic to remove users from the version control repository if they are no longer part of the team seems correct. It's good to see that the code is handling the synchronization of team members with the VCS permissions.
src/main/java/de/tum/in/www1/artemis/service/scheduled/ParticipantScoreScheduleService.java (1)
- 249-249: The change from
findById
tofindWithStudentsById
in theexecuteTask
method is consistent with the PR's objective to switch from EAGER to LAZY loading. This ensures that when a team is fetched, its members are also loaded, which is necessary for the subsequent logic.src/main/java/de/tum/in/www1/artemis/web/rest/TeamResource.java (4)
159-159: The update to use
findWithStudentsById
in theupdateTeam
method aligns with the PR's goal to ensure that student information is fetched efficiently when required. This change is necessary for the correct functioning of the method after the switch to LAZY loading.223-223: The use of
findWithStudentsByIdElseThrow
in thegetTeam
method is appropriate as it ensures that the team and its students are fetched from the database, which is necessary for the method's logic to function correctly after the switch to LAZY loading.267-267: The change in the
deleteTeam
method to usefindWithStudentsByIdElseThrow
is correct and ensures that the team and its students are loaded before deletion. Additionally, the deletion of team scores before the team itself is a good practice to maintain referential integrity in the database.283-284: The actual deletion of the team in the
deleteTeam
method is correctly placed after the deletion of team scores. This order of operations is important to avoid foreign key constraint violations in the database.src/main/java/de/tum/in/www1/artemis/service/AuthorizationCheckService.java (3)
30-30: The import of
TeamRepository
is added to support the new functionality related to team handling.57-67: The
teamRepository
field is properly declared and initialized in the constructor using dependency injection, which is consistent with best practices.563-565: The modification in the
isOwnerOfParticipation
method now handles the case where the participant is aTeam
. It fetches the team with students before checking ownership, which aligns with the PR's objective to manage lazy loading of teams and students.src/main/java/de/tum/in/www1/artemis/service/programming/ProgrammingSubmissionService.java (2)
- 163-164: The method
findFirstByParticipationIdAndCommitHashOrderByIdDescWithFeedbacksAndTeamStudents
is introduced to fetch aProgrammingSubmission
with feedbacks and team students eagerly. This change aligns with the PR objectives to optimize database interactions by removing explicit EAGER fetching and using fetch queries where necessary. Ensure that the method is correctly implemented in the repository and that it does not introduce any performance regressions.Verification successful
The previous script contained a syntax error. I will correct the pattern and re-run the ast-grep command to verify the existence and usage of the method
findFirstByParticipationIdAndCommitHashOrderByIdDescWithFeedbacksAndTeamStudents
in theProgrammingSubmissionRepository
.
The ast-grep command did not yield the expected results. I will now use ripgrep (rg) to search for the method
findFirstByParticipationIdAndCommitHashOrderByIdDescWithFeedbacksAndTeamStudents
in theProgrammingSubmissionRepository
.
The search with ripgrep has successfully located the method
findFirstByParticipationIdAndCommitHashOrderByIdDescWithFeedbacksAndTeamStudents
within theProgrammingSubmissionRepository
. The method is indeed present and is being used in theProgrammingSubmissionService.java
file. Additionally, the method is defined as a default method in the repository interface, delegating to another methodfindByParticipationIdAndCommitHashOrderByIdDescWithFeedbacksAndTeamStudents
and usingstream().findFirst().orElse(null)
to return the first result ornull
if none is found.This confirms that the method has been implemented in the repository and is being used in the service as intended by the PR objectives.
* 353-354: The method `findFirstByParticipationIdAndCommitHashOrderByIdDescWithFeedbacksAndTeamStudents` is used again to fetch a `ProgrammingSubmission` with feedbacks and team students eagerly. This is consistent with the changes made in the first hunk and should be verified for correct implementation and performance.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify the new repository method's existence and its usage in the codebase. ast-grep --lang java --pattern $'ProgrammingSubmissionRepository { $$$ findFirstByParticipationIdAndCommitHashOrderByIdDescWithFeedbacksAndTeamStudents($_, $_); $$$ }'Length of output: 736
Script:
#!/bin/bash # Corrected script to verify the new repository method's existence and its usage in the codebase. ast-grep --lang java --pattern $'class ProgrammingSubmissionRepository { $$$ findFirstByParticipationIdAndCommitHashOrderByIdDescWithFeedbacksAndTeamStudents($_, $_) { $$$ } $$$ }'Length of output: 283
Script:
#!/bin/bash # Using ripgrep to search for the method in the ProgrammingSubmissionRepository. rg "findFirstByParticipationIdAndCommitHashOrderByIdDescWithFeedbacksAndTeamStudents" -A 3 -B 3Length of output: 3663
Verification successful
The search results confirm the existence of the method
findFirstByParticipationIdAndCommitHashOrderByIdDescWithFeedbacksAndTeamStudents
within theProgrammingSubmissionRepository
. The method is used in theProgrammingSubmissionService
class, and there is also a default implementation of this method in theProgrammingSubmissionRepository
itself, which delegates to another method and processes the result to return the first submission ornull
.Based on this information, the review comment is consistent with the codebase, as the method is indeed used to fetch a
ProgrammingSubmission
with feedbacks and team students eagerly.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify the new repository method's existence and its usage in the codebase. ast-grep --lang java --pattern $'ProgrammingSubmissionRepository { $$$ findFirstByParticipationIdAndCommitHashOrderByIdDescWithFeedbacksAndTeamStudents($_, $_); $$$ }'Length of output: 736
Script:
#!/bin/bash # Correcting the ast-grep pattern to verify the existence and usage of the method in the ProgrammingSubmissionRepository. ast-grep --lang java --pattern $'class ProgrammingSubmissionRepository { $$$ findFirstByParticipationIdAndCommitHashOrderByIdDescWithFeedbacksAndTeamStudents($_, $_) { $$$ } $$$ }'Length of output: 283
Script:
#!/bin/bash # Using ripgrep to search for the method in the ProgrammingSubmissionRepository. rg "findFirstByParticipationIdAndCommitHashOrderByIdDescWithFeedbacksAndTeamStudents" -A 3 -B 3Length of output: 3663
src/main/java/de/tum/in/www1/artemis/service/ParticipationService.java (1)
- 442-445: The change in the
configureRepository
method ensures that if the participant is a team, it is eagerly loaded with its students. This is necessary for the repository configuration and aligns with the PR's objective to optimize database interactions by replacing explicit EAGER fetching with LAZY fetching and fetch queries where necessary. However, it's important to ensure that this eager loading does not introduce performance regressions elsewhere in the application.Please verify that the
teamRepository.findWithStudentsByIdElseThrow(team.getId())
method is optimized for performance and does not lead to N+1 select issues or other performance bottlenecks.src/main/java/de/tum/in/www1/artemis/repository/StudentParticipationRepository.java (1)
- 42-46: The modified query in
findByCourseIdWithEagerResultsAndEagerTeamAndEagerStudents
method now includesLEFT JOIN FETCH
forresults
,team
, andstudents
. This change aligns with the PR's objective to optimize database interactions by replacing explicit EAGER fetching with LAZY fetching and fetch queries. Ensure that the rest of the application is compatible with this change, as it may affect any service or controller that relies on the data fetched by this query.src/main/java/de/tum/in/www1/artemis/web/rest/ParticipationResource.java (1)
- 293-293: The logic here is to handle a case where there is another participation by the same student that is either inactive or finished. This is a good practice to ensure that the state of all participations is consistent. However, it's important to ensure that this logic does not introduce any side effects or race conditions, especially when dealing with the state of participations in a concurrent environment.
src/main/java/de/tum/in/www1/artemis/web/rest/ParticipationResource.java
Outdated
Show resolved
Hide resolved
src/main/java/de/tum/in/www1/artemis/service/programming/ProgrammingSubmissionService.java
Show resolved
Hide resolved
src/main/java/de/tum/in/www1/artemis/service/team/TeamImportStrategy.java
Show resolved
Hide resolved
...e/tum/in/www1/artemis/exercise/modelingexercise/compass/umlmodel/AbstractUMLDiagramTest.java
Show resolved
Hide resolved
src/main/java/de/tum/in/www1/artemis/web/websocket/team/TeamWebsocketService.java
Outdated
Show resolved
Hide resolved
src/test/java/de/tum/in/www1/artemis/DatabaseQueryCountTest.java
Outdated
Show resolved
Hide resolved
src/main/java/de/tum/in/www1/artemis/service/ParticipationAuthorizationCheckService.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- src/test/java/de/tum/in/www1/artemis/DatabaseQueryCountTest.java (2 hunks)
Files skipped from review as they are similar to previous changes (1)
- src/test/java/de/tum/in/www1/artemis/DatabaseQueryCountTest.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- src/main/java/de/tum/in/www1/artemis/repository/ProgrammingExerciseStudentParticipationRepository.java (5 hunks)
Files skipped from review as they are similar to previous changes (1)
- src/main/java/de/tum/in/www1/artemis/repository/ProgrammingExerciseStudentParticipationRepository.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-tested on TS1. No further issues found, worked well 👍
Also tested for LTI result service cases, still works
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (4)
- src/main/java/de/tum/in/www1/artemis/service/ResultService.java (1 hunks)
- src/main/java/de/tum/in/www1/artemis/service/programming/ProgrammingSubmissionService.java (2 hunks)
- src/main/java/de/tum/in/www1/artemis/service/programming/ProgrammingTriggerService.java (2 hunks)
- src/main/java/de/tum/in/www1/artemis/web/websocket/team/TeamWebsocketService.java (1 hunks)
Files skipped from review as they are similar to previous changes (3)
- src/main/java/de/tum/in/www1/artemis/service/ResultService.java
- src/main/java/de/tum/in/www1/artemis/service/programming/ProgrammingSubmissionService.java
- src/main/java/de/tum/in/www1/artemis/service/programming/ProgrammingTriggerService.java
Additional comments: 1
src/main/java/de/tum/in/www1/artemis/web/websocket/team/TeamWebsocketService.java (1)
- 29-29: The added comment clarifies the use cases for the
sendTeamAssignmentUpdate
method, which is helpful for understanding when and how to use the method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good, successfully tested on ts1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
manually tested on ts1, works as expected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Manually tested on ts6, works as expected.
Checklist
General
Server
Motivation and Context
In #7719, the migration to Hibernate 6 introduced circular references in some produced SQL queries. To mitigate this effect, we replace explicit EAGER references on models with fetch queries wherever necessary.
This PR affects the relation between Teams and Students
Description
We removed the explicit EAGER, added a student fetch to some queries and replaced certain query usages where fetching students is required.
Steps for Testing
Prerequisites:
Testserver States
Note
These badges show the state of the test servers.
Green = Currently available, Red = Currently locked
Review Progress
Performance Review
Code Review
Manual Tests
Test Coverage
No additional assertions, but changed production lines
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
Documentation
Tests