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: Speedup loading of active courses #9768

Closed
wants to merge 5 commits into from

Conversation

Strohgelaender
Copy link
Contributor

@Strohgelaender Strohgelaender commented Nov 13, 2024

Checklist

General

Server

Motivation and Context

While reviewing PR #9727 I spotted a filter call that could be moved into a database query to improve performance.

Description

We now directly filter out inactive courses at the database level to avoid loading to many objects.

Steps for Testing

Navigate to Aretmis -> Course management and check that the currently active courses are diplayed correctly.

Testserver States

Note

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







Review Progress

Performance Review

  • I (as a reviewer) confirm that the client changes (in particular related to REST calls and UI responsiveness) are implemented with a very good performance even for very large courses with more than 2000 students.
  • I (as a reviewer) confirm that the server changes (in particular related to database calls) are implemented with a very good performance even for very large courses with more than 2000 students.

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Performance Tests

  • Test 1
  • Test 2

Summary by CodeRabbit

  • New Features

    • Introduced a new method to retrieve active courses for users with tutor roles, enhancing course management.
  • Improvements

    • Streamlined the retrieval process for courses, improving efficiency and reducing complexity in the code.
  • Bug Fixes

    • Updated method naming conventions for clarity and consistency.

@github-actions github-actions bot added server Pull requests that update Java code. (Added Automatically!) core Pull requests that affect the corresponding module labels Nov 13, 2024
@Strohgelaender Strohgelaender marked this pull request as ready for review November 13, 2024 11:05
@Strohgelaender Strohgelaender requested a review from a team as a code owner November 13, 2024 11:05
Copy link

coderabbitai bot commented Nov 13, 2024

Walkthrough

The changes involve updates to the CourseRepository and CourseResource classes. In CourseRepository, a method has been renamed and a new method added to enhance course retrieval based on user roles and course activity status. In CourseResource, the getCoursesForTutors method has been refactored to improve efficiency by directly querying for active courses, eliminating unnecessary intermediate variables, while maintaining its original functionality.

Changes

File Path Change Summary
src/main/java/de/tum/cit/aet/artemis/core/repository/CourseRepository.java - Renamed method: findCoursesForAtLeastTutorWithGroupsfindAllCoursesForAtLeastTutorWithGroups
- Added method: findActiveCoursesForAtLeastTutorWithGroups to retrieve active courses based on user group membership.
src/main/java/de/tum/cit/aet/artemis/core/web/CourseResource.java - Refactored getCoursesForTutors method to directly query for active courses, improving efficiency and reducing cyclomatic complexity. No changes to method signatures.

Suggested labels

ready for review, performance, small

Suggested reviewers

  • krusche
  • florian-glombik
  • MaximilianAnzinger

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

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: 0

🧹 Outside diff range and nitpick comments (1)
src/main/java/de/tum/cit/aet/artemis/core/web/CourseResource.java (1)

451-454: Great optimization: Moving filtering to the database level!

The refactoring improves performance by leveraging database-level filtering instead of in-memory filtering. This is particularly beneficial when dealing with large datasets.

Consider adding a comment explaining the performance optimization for future maintainers:

    if (onlyActive) {
        // only include courses that have NOT been finished
        final var now = ZonedDateTime.now();
+       // Filtering is done at database level for better performance
        return courseRepository.findActiveCoursesForAtLeastTutorWithGroups(user.getGroups(), authCheckService.isAdmin(user), now);
    }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 054476c and bf6296a.

📒 Files selected for processing (2)
  • src/main/java/de/tum/cit/aet/artemis/core/repository/CourseRepository.java (1 hunks)
  • src/main/java/de/tum/cit/aet/artemis/core/web/CourseResource.java (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/main/java/de/tum/cit/aet/artemis/core/repository/CourseRepository.java (1)

Pattern src/main/java/**/*.java: naming:CamelCase; principles:{single_responsibility,small_methods,no_duplication}; db:{perf_queries,datetime_not_timestamp}; rest:{stateless,singleton,delegate_logic,http_only,minimal_dtos}; dtos:{java_records,no_entities,min_data,single_resp}; di:constructor_injection; kiss:simple_code; file_handling:os_indep_paths; practices:{least_access,avoid_transactions,code_reuse,static_member_ref,prefer_primitives}; sql:{param_annotation,uppercase,avoid_subqueries};java:avoid_star_imports

src/main/java/de/tum/cit/aet/artemis/core/web/CourseResource.java (1)

Pattern src/main/java/**/*.java: naming:CamelCase; principles:{single_responsibility,small_methods,no_duplication}; db:{perf_queries,datetime_not_timestamp}; rest:{stateless,singleton,delegate_logic,http_only,minimal_dtos}; dtos:{java_records,no_entities,min_data,single_resp}; di:constructor_injection; kiss:simple_code; file_handling:os_indep_paths; practices:{least_access,avoid_transactions,code_reuse,static_member_ref,prefer_primitives}; sql:{param_annotation,uppercase,avoid_subqueries};java:avoid_star_imports

🔇 Additional comments (2)
src/main/java/de/tum/cit/aet/artemis/core/repository/CourseRepository.java (2)

583-584: LGTM! Method rename improves clarity.

The rename from findCoursesForAtLeastTutorWithGroups to findAllCoursesForAtLeastTutorWithGroups better describes the method's behavior by explicitly indicating it returns all courses.


585-594: LGTM! Efficient implementation of active courses filtering.

The new method efficiently implements the PR's performance objective by:

  1. Filtering active courses directly at the database level
  2. Using proper parameter binding for the timestamp
  3. Following the repository's consistent pattern for handling course dates

This implementation prevents unnecessary loading of inactive courses, reducing both database load and memory usage.

Copy link

@Longppham Longppham left a comment

Choose a reason for hiding this comment

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

I tested this PR on TS4 as a student (Was not specified which to choose?) Following the instructions, I went to artemis and then clicked on course management which lead then to the screenshot I attached here. When I check the box show only active courses, nothing changes.
Works like described.

image

image

image

@Strohgelaender
Copy link
Contributor Author

In the current courses, it says 76 but after clicking course management, only 1 Course is shown.

On the front page all courses (where you are at least student) are shown, on the course management page you only see courses where you are at least tutor. So that's a correct behaviour.

@Longppham
Copy link

In the current courses, it says 76 but after clicking course management, only 1 Course is shown.

On the front page all courses (where you are at least student) are shown, on the course management page you only see courses where you are at least tutor. So that's a correct behaviour.

Perfect! I was not sure how it worked for my account! Should i edit my old comment?

Copy link

@HawKhiem HawKhiem 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 TS1 with both tutor and instructor test accounts. All active courses were displayed correctly

Copy link

@sawys777 sawys777 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 TS1, everything worked as expected.

Copy link

@Cathy0123456789 Cathy0123456789 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 TS1. Active courses are displayed correctly

Copy link

@flbrgit flbrgit 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 TS4. Everything works as expected

Copy link

@JerroyTan JerroyTan 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 TS3]
Active courses displayed correctly without problem.

@github-actions github-actions bot added deployment-error Added by deployment workflows if an error occured and removed deploy:artemis-test1 labels Nov 25, 2024
@Strohgelaender Strohgelaender removed the deployment-error Added by deployment workflows if an error occured label Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Pull requests that affect the corresponding module ready for review server Pull requests that update Java code. (Added Automatically!)
Projects
Status: Work In Progress
Development

Successfully merging this pull request may close these issues.