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: Avoid database queries with pagination and left join fetch #8741

Merged
merged 76 commits into from
Aug 8, 2024

Conversation

krusche
Copy link
Member

@krusche krusche commented Jun 4, 2024

Checklist

General

Server

Motivation and Context

Pagination combined with fetching ("left join fetch") leads to potential performance issues (see https://vladmihalcea.com/hibernate-query-fail-on-pagination-over-collection-fetch) and to ugly warnings in the logs HHH90003004: firstResult/maxResults specified with collection fetch; applying in memory

Description

  • We already added TODOs into the code and now activated the setting hibernate.query.fail_on_pagination_over_collection_fetch: true in the src and test code to find all places that combine pagination with left join fetch.
  • To solve the issue, we need to split the query into two parts:
    1. Find the ids without any additional fetching (potentially including joins for conditions in the where clause)
    2. Use the ids to load the actual objects with additional fetching of related objects
  • In case of sorting (order by), we might need to make sure that the custom order is maintained in the second query of afterwards in Java.

A good example of this (based on the Specification API) can be found in the changes of #5257.

Steps for Testing

The database queries could influence these parts of the application:

  1. Test programming exercises and everything around them.
  2. Test Iris.
  3. Test conversations in a course.
  4. Exam mode testing.
    You can test one of them.
    I created a course with all types of exercises on ts5 in my test course, and you can take an exam there as well.

Also, you are welcome to test other features that are not mentioned in this list.

Testserver States

Note

These badges show the state of the test servers.
Green = Currently available, Red = Currently locked






Review Progress

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Exam Mode Test

  • Test 1
  • Test 2

Test Coverage

Server

Class/File Line Coverage Confirmation (assert/expect)
BuildJobRepository.java 0% ✅ ❌
PersistenceAuditEventRepository.java 87% ✅ ❌
ProgrammingSubmissionRepository.java 77% ✅ ❌
ResultRepository.java 94% ✅ ❌
StudentParticipationRepository.java 93% ✅ ❌
UserRepository.java 86% ✅ ❌
RepositoryImpl.java 66% ✅ ❌
CoverageReportRepository.java 82% ✅ ❌
IrisCourseChatSessionRepository.java 0% ✅ ❌
IrisExerciseChatSessionRepository.java 80% ✅ ❌
IrisMessageRepository.java 0% ✅ ❌
PlagiarismResultRepository.java 100%
AuditEventService.java 100%
SubmissionService.java 90% ✅ ❌
SharedQueueManagementService.java 93% ✅ ❌
Lti13Service.java 88% ✅ ❌
ProgrammingExerciseGitDiffReportService.java 81% ✅ ❌
TestwiseCoverageService.java 69% ✅ ❌
ConversationService.java 93% ✅ ❌
ProgrammingExerciseGradingService.java 96% ✅ ❌
ProgrammingSubmissionService.java 87% ✅ ❌
CourseResource.java 89% ✅ ❌
ModelingExerciseResource.java 96% ✅ ❌
ParticipationResource.java 87% ✅ ❌
TextExerciseResource.java 96% ✅ ❌
ConversationResource.java 92% ✅ ❌
ProgrammingExercisePlagiarismResource.java 86% ✅ ❌

Client coverage was not changed.

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced query performance across various repositories for more efficient data retrieval.
  • New Features

    • Introduced methods to search and filter users by login or name within groups, courses, and conversations.
    • Added new methods to retrieve detailed information on programming submissions, results, and coverage reports.
    • Enhanced message retrieval capabilities with new methods in the IrisMessage repository, improving error handling and efficiency.
  • Refactor

    • Refined existing methods in repositories for optimized query execution and improved readability.
    • Updated repository method calls to enhance specificity and performance.
  • Documentation

    • Improved comments and Javadoc annotations for better clarity and understanding.
  • Chores

    • Updated repository method signatures and imports for better code maintainability and performance.

@github-actions github-actions bot added tests config-change Pull requests that change the config in a way that they require a deployment via Ansible. labels Jun 4, 2024
@dmytropolityka dmytropolityka self-assigned this Jun 6, 2024
@github-actions github-actions bot added the server Pull requests that update Java code. (Added Automatically!) label Jun 10, 2024
@dmytropolityka dmytropolityka marked this pull request as ready for review June 17, 2024 08:07
@dmytropolityka dmytropolityka requested a review from a team as a code owner June 17, 2024 08:07
Copy link

coderabbitai bot commented Jun 17, 2024

Walkthrough

Recent updates across multiple repository files significantly enhance data retrieval efficiency and optimize query performance for various entities such as programming submissions, results, and users. New methods have been introduced, and existing ones have been refactored for improved functionality and clarity. These changes collectively aim to streamline access to data and boost overall system performance, particularly within the context of programming exercises and user management.

Changes

File Path Change Summary
src/main/java/de/tum/in/www1/artemis/repository/.../ProgrammingSubmissionRepository.java Enhanced querying capabilities for programming submissions with new methods to fetch structured data and optimized retrieval based on participation ID and submission date.
src/main/java/de/tum/in/www1/artemis/repository/.../ResultRepository.java Introduced methods for improved result retrieval, including feedback and test cases integration, while optimizing existing queries for better performance and readability.
src/main/java/de/tum/in/www1/artemis/repository/.../StudentParticipationRepository.java Added new and default methods to enhance effective data retrieval based on exercise ID and student name, improving overall functionality and performance.
src/main/java/de/tum/in/www1/artemis/repository/.../UserRepository.java Introduced extensive new search methods that enhance flexibility and performance for user-related queries across various contexts.
src/main/java/de/tum/in/www1/artemis/repository/.../CoverageReportRepository.java Improved data handling in coverage reports with new methods and optimized query processes, enhancing retrieval efficiency.
src/main/java/de/tum/in/www1/artemis/repository/.../IrisMessageRepository.java Added error handling methods and improved message retrieval, ensuring better management of message entities and enhancing performance.

Sequence Diagram(s)

Sequence Diagram for Programming Submission Result Retrieval

sequenceDiagram
    participant Student as Student
    participant CourseOverview as CourseOverview
    participant ProgrammingSubmissionRepository as ProgrammingSubmissionRepository

    Student->>CourseOverview: request latest submission results
    CourseOverview->>ProgrammingSubmissionRepository: findFirstIdByParticipationIdOrderBySubmissionDateDesc(participationId, Pageable)
    ProgrammingSubmissionRepository-->>CourseOverview: List<ProgrammingSubmissionIdAndSubmissionDateDTO>
    CourseOverview-->>Student: display latest submission results
Loading

Possibly Related Issues


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Copy link
Member

@julian-christl julian-christl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code

Copy link
Contributor

@JohannesStoehr JohannesStoehr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code

Copy link
Contributor

@EneaGore EneaGore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-approve

Copy link
Contributor

@SimonEntholzer SimonEntholzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on TS6 and didn't encounter any issues

Copy link
Collaborator

@MaximilianAnzinger MaximilianAnzinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love the extensive usage of derived queries 👍
LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
config-change Pull requests that change the config in a way that they require a deployment via Ansible. documentation maintainer-approved The feature maintainer has approved the PR ready for review ready to merge server Pull requests that update Java code. (Added Automatically!) tests
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.