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

Communication: Fix an issue with duplicated posts on course wide search #9819

Merged
merged 2 commits into from
Nov 20, 2024

Conversation

cremertim
Copy link
Contributor

@cremertim cremertim commented Nov 19, 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, the search returns for each answer post an occurences in the course wide search, since we do not filter on duplicates. This PR fixes the issue

Description

Steps for Testing

Prerequisites:

  • 1 Instructor
  1. Log in to Artemis
  2. Navigate to the Communication Section of a Course
  3. Search for an exisiting post that has answer posts
  4. Verify, the exisiting post is only shown once in the search

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

Screenshots

Before:
image

After:
image

Summary by CodeRabbit

  • New Features
    • Enhanced post retrieval to ensure only unique post IDs are returned, improving data accuracy and reducing redundancy.

@cremertim cremertim self-assigned this Nov 19, 2024
@cremertim cremertim requested a review from a team as a code owner November 19, 2024 13:03
@github-actions github-actions bot added server Pull requests that update Java code. (Added Automatically!) communication Pull requests that affect the corresponding module labels Nov 19, 2024
Copy link

coderabbitai bot commented Nov 19, 2024

Walkthrough

The changes in this pull request involve modifications to the CustomPostRepositoryImpl class, specifically within the findPostIdsWithSpecification method. The update introduces a new import for LinkedHashSet, and a new list, uniquePostIds, is created to eliminate duplicates from the original postIds list. The method now returns uniquePostIds, ensuring that the output contains only unique post IDs while maintaining the original logic.

Changes

File Path Change Summary
src/main/java/de/tum/cit/aet/artemis/communication/repository/CustomPostRepositoryImpl.java Modified findPostIdsWithSpecification to create and return a list of unique post IDs. Added import for LinkedHashSet.

Possibly related PRs

Suggested labels

tests, ready for review

Suggested reviewers

  • JohannesStoehr
  • sachmii
  • florian-glombik
  • HanyangXu0508
  • rabeatwork
  • Malekos74
  • krusche

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 (2)
src/main/java/de/tum/cit/aet/artemis/communication/repository/CustomPostRepositoryImpl.java (2)

55-56: Consider extracting deduplication logic and improving documentation.

While the implementation is correct, consider these improvements:

  1. Extract the deduplication logic into a reusable utility method
  2. Enhance the comment to explain why duplicates occur (e.g., due to answer posts relationship)

Consider applying this refactor:

- // removes all duplicates from the answer posts
- List<Long> uniquePostIds = new ArrayList<>(new LinkedHashSet<>(postIds));
+ // Answer posts can appear multiple times in search results due to their relationship with parent posts
+ List<Long> uniquePostIds = PostRepositoryUtil.deduplicateIds(postIds);

Add this utility class:

public class PostRepositoryUtil {
    public static List<Long> deduplicateIds(List<Long> ids) {
        return new ArrayList<>(new LinkedHashSet<>(ids));
    }
}

Line range hint 33-73: Consider SQL-level deduplication for better performance.

Instead of deduplicating in memory, consider using SQL DISTINCT in the query for better performance with large datasets. This would reduce the amount of data transferred from the database.

Consider modifying the query like this:

 CriteriaQuery<Long> criteriaQuery = builder.createQuery(Long.class);
 Root<Post> root = criteriaQuery.from(Post.class);
-criteriaQuery.select(root.get(Post_.ID));
+criteriaQuery.select(root.get(Post_.ID)).distinct(true);

This would:

  1. Handle deduplication at the database level
  2. Reduce memory usage and processing time
  3. Ensure consistent counts for pagination
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 745c7f7 and 1b7239c.

📒 Files selected for processing (1)
  • src/main/java/de/tum/cit/aet/artemis/communication/repository/CustomPostRepositoryImpl.java (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/main/java/de/tum/cit/aet/artemis/communication/repository/CustomPostRepositoryImpl.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/communication/repository/CustomPostRepositoryImpl.java (2)

5-5: LGTM! Good choice of data structure.

LinkedHashSet is an appropriate choice as it maintains insertion order while ensuring uniqueness.


73-73: Verify pagination behavior with deduplicated results.

The count query might include duplicates while the returned list is deduplicated. This could lead to pagination inconsistencies where:

  1. The total count is higher than actual unique posts
  2. Pages might have fewer items than expected

Let's verify the impact:

@cremertim cremertim changed the title ´Communication´ Only show post once per search Communication Only show post once per search Nov 19, 2024
@cremertim cremertim changed the title Communication Only show post once per search Communication: Only show post once per search Nov 19, 2024
@cremertim cremertim changed the title Communication: Only show post once per search Communication: Remove post duplication on course wide search Nov 19, 2024
@sachmii sachmii temporarily deployed to artemis-test5.artemis.cit.tum.de November 19, 2024 19:15 — with GitHub Actions Inactive
Copy link

@sachmii sachmii 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 TS5, worked just fine. No duplicated were shown

Copy link

⚠️ Unable to deploy to test servers ⚠️

Testserver "artemis-test5.artemis.cit.tum.de" is already in use by PR #9824.

@github-actions github-actions bot added the deployment-error Added by deployment workflows if an error occured label Nov 19, 2024
@HawKhiem HawKhiem added deploy:artemis-test5 and removed deployment-error Added by deployment workflows if an error occured labels Nov 19, 2024
@HawKhiem HawKhiem temporarily deployed to artemis-test5.artemis.cit.tum.de November 19, 2024 19:58 — with GitHub Actions Inactive
@github-actions github-actions bot mentioned this pull request Nov 19, 2024
7 tasks
Copy link

@vinceclifford vinceclifford 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 TS5, works 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 TS5. Works as described

Copy link

@ItsaaaMeMario ItsaaaMeMario 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 TS5, search result only shows up once, works as expected.

Copy link

@zagemello zagemello 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 TS5, all works as expected.

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.

Thx for looking into it again 👍

@krusche krusche changed the title Communication: Remove post duplication on course wide search Communication: Fix an issue with duplicated posts on course wide search Nov 20, 2024
@krusche krusche added this to the 7.7.2 milestone Nov 20, 2024
@krusche krusche merged commit b4a6886 into develop Nov 20, 2024
52 of 56 checks passed
@krusche krusche deleted the bugfix/communication/show-post-once-per-search branch November 20, 2024 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
communication Pull requests that affect the corresponding module ready to merge server Pull requests that update Java code. (Added Automatically!)
Projects
Status: Merged
Development

Successfully merging this pull request may close these issues.

[Communication] Seeing the same message multiple times after a search
9 participants