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: Remove unused reference in posting models #10075

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

PaRangger
Copy link
Contributor

@PaRangger PaRangger commented Dec 23, 2024

Checklist

General

Server

  • Important: I implemented the changes with a very good performance and prevented too many (unnecessary) and too complex database calls.
  • I strictly followed the principle of data economy for all database calls.
  • I strictly followed the server coding and design guidelines.
  • I documented the Java code using JavaDoc style.

Motivation and Context

Currently there is a unused relation to SavedPosts declared in the Post and AnswerPost models. This reference also causes multiple warnings when starting the server:

.../Artemis/src/main/java/de/tum/cit/aet/artemis/communication/domain/Post.java:63: warning: member 'postId' of 'SavedPost' is not annotated '@ManyToOne'
    @OneToMany(mappedBy = "postId", cascade = CascadeType.REMOVE, orphanRemoval = true, fetch = FetchType.LAZY)

Description

I removed the unused relation in the models. Since the relation was tagged with a cascade, i added some deletion logic to the corresponding services when deleting posts/answer posts. Additionally, I slightly offset the cronjob that deletes orphaned SavedPosts to the one that deletes old completed/archived SavedPosts.

Steps for Testing

Prerequisites:

  • 1 Student/Tutor/Instructor
  • 1 Course with communication enabled
  1. Log in to Artemis
  2. Navigate to course
  3. Navigate to the communication tab
  4. If none exists, create some posts and answer posts
  5. Save a post and an answer post
  6. Check if they show up in the "In Progress" section of the sidebar
  7. Delete the post and answer post that you just saved
  8. Everything should work as it did before

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

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Test Coverage

Summary by CodeRabbit

  • New Features

    • Added a method to retrieve saved posts based on post ID and type.
  • Bug Fixes

    • Enhanced cleanup processes to delete associated saved posts when an answer message or a message is deleted.
  • Chores

    • Updated the scheduling time for the cleanup of orphaned saved posts.

@PaRangger PaRangger self-assigned this Dec 23, 2024
@github-actions github-actions bot added server Pull requests that update Java code. (Added Automatically!) communication Pull requests that affect the corresponding module labels Dec 23, 2024
@PaRangger PaRangger added chore component:Communication communication Pull requests that affect the corresponding module server Pull requests that update Java code. (Added Automatically!) deploy:artemis-test5 and removed server Pull requests that update Java code. (Added Automatically!) communication Pull requests that affect the corresponding module labels Dec 23, 2024
@PaRangger PaRangger marked this pull request as ready for review December 23, 2024 16:42
@PaRangger PaRangger requested a review from a team as a code owner December 23, 2024 16:42
Copy link

coderabbitai bot commented Dec 23, 2024

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 pmd (7.8.0)
src/main/java/de/tum/cit/aet/artemis/communication/repository/SavedPostRepository.java

The following rules are missing or misspelled in your ruleset file category/vm/bestpractices.xml: BooleanInstantiation, DontImportJavaLang, DuplicateImports, EmptyFinallyBlock, EmptyIfStmt, EmptyInitializer, EmptyStatementBlock, EmptyStatementNotInLoop, EmptySwitchStatements, EmptySynchronizedBlock, EmptyTryBlock, EmptyWhileStmt, ExcessiveClassLength, ExcessiveMethodLength, ImportFromSamePackage, MissingBreakInSwitch, SimplifyBooleanAssertion. Please check your ruleset configuration.

src/main/java/de/tum/cit/aet/artemis/communication/service/AnswerMessageService.java

The following rules are missing or misspelled in your ruleset file category/vm/bestpractices.xml: BooleanInstantiation, DontImportJavaLang, DuplicateImports, EmptyFinallyBlock, EmptyIfStmt, EmptyInitializer, EmptyStatementBlock, EmptyStatementNotInLoop, EmptySwitchStatements, EmptySynchronizedBlock, EmptyTryBlock, EmptyWhileStmt, ExcessiveClassLength, ExcessiveMethodLength, ImportFromSamePackage, MissingBreakInSwitch, SimplifyBooleanAssertion. Please check your ruleset configuration.

src/main/java/de/tum/cit/aet/artemis/communication/service/ConversationMessagingService.java

The following rules are missing or misspelled in your ruleset file category/vm/bestpractices.xml: BooleanInstantiation, DontImportJavaLang, DuplicateImports, EmptyFinallyBlock, EmptyIfStmt, EmptyInitializer, EmptyStatementBlock, EmptyStatementNotInLoop, EmptySwitchStatements, EmptySynchronizedBlock, EmptyTryBlock, EmptyWhileStmt, ExcessiveClassLength, ExcessiveMethodLength, ImportFromSamePackage, MissingBreakInSwitch, SimplifyBooleanAssertion. Please check your ruleset configuration.

  • 1 others

Walkthrough

This pull request introduces changes to several Java classes in the Artemis communication domain, primarily focusing on the handling of saved posts. The modifications include removing savedPosts fields from AnswerPost and Post classes, updating repository methods, adding a new method to SavedPostRepository, and modifying service classes to handle saved post deletion. The changes aim to streamline the management of saved posts across different entity types, with a particular emphasis on cleanup and retrieval processes.

Changes

File Change Summary
src/.../AnswerPost.java Removed savedPosts field and its getter method
src/.../Post.java Removed savedPosts field and its getter method
src/.../ConversationMessageRepository.java Removed left join fetch for savedPosts, made configureSearchSpecification private
src/.../SavedPostRepository.java Added findSavedPostByPostIdAndPostType method
src/.../AnswerMessageService.java Added logic to delete saved posts when deleting an answer message
src/.../ConversationMessagingService.java Added logic to delete saved posts when deleting a message
src/.../SavedPostScheduleService.java Modified cron expression for cleanupOrphanedSavedPosts method

Possibly related PRs

Suggested Labels

tests, ready for review, code quality, bugfix

Suggested Reviewers

  • krusche
  • JohannesStoehr
  • HanyangXu0508
  • Feras797
  • asliayk
  • JanaNF
  • edkaya
  • muradium

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 97c0636 and 74a3d4d.

📒 Files selected for processing (7)
  • src/main/java/de/tum/cit/aet/artemis/communication/domain/AnswerPost.java (0 hunks)
  • src/main/java/de/tum/cit/aet/artemis/communication/domain/Post.java (0 hunks)
  • src/main/java/de/tum/cit/aet/artemis/communication/repository/ConversationMessageRepository.java (0 hunks)
  • src/main/java/de/tum/cit/aet/artemis/communication/repository/SavedPostRepository.java (1 hunks)
  • src/main/java/de/tum/cit/aet/artemis/communication/service/AnswerMessageService.java (2 hunks)
  • src/main/java/de/tum/cit/aet/artemis/communication/service/ConversationMessagingService.java (2 hunks)
  • src/main/java/de/tum/cit/aet/artemis/communication/service/SavedPostScheduleService.java (1 hunks)
💤 Files with no reviewable changes (3)
  • src/main/java/de/tum/cit/aet/artemis/communication/domain/Post.java
  • src/main/java/de/tum/cit/aet/artemis/communication/domain/AnswerPost.java
  • src/main/java/de/tum/cit/aet/artemis/communication/repository/ConversationMessageRepository.java
🧰 Additional context used
📓 Path-based instructions (4)
src/main/java/de/tum/cit/aet/artemis/communication/repository/SavedPostRepository.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/communication/service/ConversationMessagingService.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/communication/service/SavedPostScheduleService.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/communication/service/AnswerMessageService.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 (6)
src/main/java/de/tum/cit/aet/artemis/communication/service/SavedPostScheduleService.java (1)

48-48: Cron expression changed from midnight to 12:05 AM.
This is a straightforward scheduling update. Just ensure that 12:05 AM is indeed the intended time for cleanup.

src/main/java/de/tum/cit/aet/artemis/communication/repository/SavedPostRepository.java (1)

49-57: New repository method for retrieving posts by ID and type.
Returning a listing of saved posts based on the (postId, postType) pair is clear and aligned with typical query patterns. Consider verifying that an index exists on these columns if performance becomes a concern for large data volumes.

✅ Verification successful

Let me gather information about the database schema and any existing indexes by searching through the codebase.


Let me search for any existing index definitions in the database migration files.


Index already exists for the queried columns.
The database schema already includes a composite index IDX_SAVED_POST_USER_ID_POST_ID_POST_TYPE that covers the columns used in the query method (post_id and post_type). This index will help optimize the performance of findSavedPostByPostIdAndPostType method.

🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Search for schema definitions or migration files related to SavedPost
fd -e sql -e java saved.*post -i

# Look for SavedPost entity definition to check existing indexes
rg -i "class SavedPost" -A 10

Length of output: 11874


Script:

#!/bin/bash
# Search for database migration files that might contain index definitions for SavedPost
fd -e sql changelog
rg -i "saved_post" -A 5 -B 5 $(fd -e sql changelog)

Length of output: 17132

src/main/java/de/tum/cit/aet/artemis/communication/service/AnswerMessageService.java (2)

15-15: Import statement for PostingType is coherent.
It allows usage of the enumerated post types.


213-216: Deletion of saved posts tied to the answer message.
Well-structured approach to maintain data integrity. If concurrency or cascading operations occur, ensure each deletion is properly transactionally handled. Otherwise, this looks good.

src/main/java/de/tum/cit/aet/artemis/communication/service/ConversationMessagingService.java (2)

30-30: Import statement for PostingType.
Necessary addition for enumerating post types.


375-378: Deletion of saved posts tied to the conversation message.
Consistent with the approach in AnswerMessageService. Helps maintain data consistency by removing orphaned references. Ensure that transactional boundaries properly handle the cascade of deletions.


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore communication Pull requests that affect the corresponding module component:Communication ready for review server Pull requests that update Java code. (Added Automatically!)
Projects
Status: Work In Progress
Status: Todo
Development

Successfully merging this pull request may close these issues.

1 participant