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: Fix duplicate server calls for messages when selecting a conversation #9611

Conversation

PaRangger
Copy link
Contributor

@PaRangger PaRangger commented Oct 27, 2024

Checklist

General

Client

  • Important: I implemented the changes with a very good performance, prevented too many (unnecessary) REST calls and made sure the UI is responsive, even with large data (e.g. using paging).
  • I strictly followed the client coding and design guidelines.

Motivation and Context

Addresses #9496

When selecting a channel the /course/id/messages api is called twice. This is inefficient and also creates a flashing ui effect of the messages appearing shortly, dissapearing and appearing again.

376960509-cd1d3567-5375-4c68-9806-498abe65d56f

Description

I added a check that compares the current active conversation with the one the metis service provides. DistinctUntilChanged did not seem to work in this scenario, so i compared the id's of the conversations.

Steps for Testing

Prerequisites:

  • 1 Student
  • 1 Course with communication enabled
  • Open the "Network" Tab in the Browser Debug Window
  1. Log in to Artemis
  2. Navigate to course
  3. Navigate to the communication tab
  4. Select channels and verify if the messages api is called once per channel

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

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Test Coverage

Summary by CodeRabbit

  • Bug Fixes
    • Improved efficiency in handling active conversations by preventing unnecessary updates when the conversation has not changed.

@github-actions github-actions bot added the client Pull requests that update TypeScript code. (Added Automatically!) label Oct 27, 2024
@PaRangger PaRangger added communication Pull requests that affect the corresponding module small deploy:artemis-test5 labels Oct 27, 2024
@PaRangger PaRangger temporarily deployed to artemis-test5.artemis.cit.tum.de October 27, 2024 16:00 — with GitHub Actions Inactive
@PaRangger PaRangger marked this pull request as ready for review October 27, 2024 16:06
@PaRangger PaRangger requested a review from a team as a code owner October 27, 2024 16:06
Copy link

coderabbitai bot commented Oct 27, 2024

Walkthrough

The changes in this pull request focus on the ConversationMessagesComponent class, specifically enhancing the subscribeToActiveConversation method. A conditional check is introduced to prevent unnecessary updates when the active conversation remains unchanged. This optimization improves the efficiency of active conversation handling without altering the overall structure or functionality of the component.

Changes

File Change Summary
src/main/webapp/app/overview/course-conversations/layout/conversation-messages/conversation-messages.component.ts Added a conditional check in subscribeToActiveConversation to exit early if the active conversation has not changed.

Possibly related PRs

Suggested labels

tests, bugfix, ready for review, component:Communication

Suggested reviewers

  • krusche
  • SimonEntholzer
  • edkaya
  • florian-glombik

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between a3b7022 and 3bf8bf5.

📒 Files selected for processing (1)
  • src/main/webapp/app/overview/course-conversations/layout/conversation-messages/conversation-messages.component.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/webapp/app/overview/course-conversations/layout/conversation-messages/conversation-messages.component.ts

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/webapp/app/overview/course-conversations/layout/conversation-messages/conversation-messages.component.ts (2)

Line range hint 1-276: Consider breaking down the component for better maintainability.

While the current changes are effective, the component handles multiple responsibilities. Consider the following architectural improvements:

  1. Extract search functionality into a dedicated search service
  2. Move post management logic to a separate service
  3. Create a custom directive for scroll handling

This would improve:

  • Testability: Smaller, focused units are easier to test
  • Maintainability: Separation of concerns makes the code easier to maintain
  • Reusability: Services can be reused across components

Would you like me to provide a detailed refactoring plan for any of these suggestions?


Line range hint 52-52: Consider a more descriptive name for the search Subject.

The search$ Subject could be renamed to better indicate its purpose, e.g., searchTerms$ or searchQuery$, following Angular naming conventions for Observables.

-    private readonly search$ = new Subject<string>();
+    private readonly searchTerms$ = new Subject<string>();
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6e1c562 and a3b7022.

📒 Files selected for processing (1)
  • src/main/webapp/app/overview/course-conversations/layout/conversation-messages/conversation-messages.component.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/main/webapp/app/overview/course-conversations/layout/conversation-messages/conversation-messages.component.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

🔇 Additional comments (1)
src/main/webapp/app/overview/course-conversations/layout/conversation-messages/conversation-messages.component.ts (1)

110-112: LGTM! Effective solution to prevent duplicate API calls.

The implementation efficiently prevents duplicate processing when the conversation hasn't changed, directly addressing the issue of duplicate API calls. The use of optional chaining ensures null safety.

Let's verify the fix prevents duplicate API calls:

✅ Verification successful

Based on the results from our verification scripts, I can now provide a final response:

Verified: The duplicate API call prevention is correctly implemented

The implementation is sound because:

  • The subscribeToActiveConversation method is used consistently across components (header, messages, and parent)
  • Each component properly implements unsubscribe patterns with takeUntil
  • The ID comparison check in the messages component (if (this._activeConversation?.id === conversation.id)) is the only place where message loading is triggered via onActiveConversationChange()
  • The change only affects the messages component's subscription, leaving other components' behavior intact
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the messages API endpoint is only called once per conversation change
# Look for other potential duplicate API call patterns in the codebase

# Test 1: Check for other subscriptions to activeConversation$ that might trigger duplicate calls
rg -l "activeConversation\$.*subscribe" 

# Test 2: Verify proper unsubscribe handling in components using activeConversation$
ast-grep --pattern 'takeUntil.*activeConversation\$'

Length of output: 219


Script:

#!/bin/bash
# Let's try a different approach to verify the subscription patterns

# Check for activeConversation usage patterns
rg -A 5 "activeConversation\$" --type ts

# Look for message API endpoint calls
rg -A 5 "/course/.*/messages" --type ts

# Check for subscription patterns in the component
rg -A 10 "subscribeToActiveConversation" --type ts

Length of output: 9811


Script:

#!/bin/bash
# Let's examine the message loading implementation to verify the fix

# Look for message loading implementation
rg -A 10 "onActiveConversationChange" --type ts

# Check for message API endpoint calls in the service
rg -A 5 "getMessages" --type ts

# Look for the message service implementation
rg -A 10 "class.*MessageService" --type ts

Length of output: 4697

coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 27, 2024
HawKhiem
HawKhiem previously approved these changes Oct 27, 2024
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 TS4. Click through multiple channels, each time the message api is called once.

image

@PaRangger PaRangger dismissed stale reviews from HawKhiem and coderabbitai[bot] via 1d2c3f5 October 27, 2024 20:20
@github-actions github-actions bot removed the communication Pull requests that affect the corresponding module label Oct 27, 2024
…on/fix-thread-loading-twice-when-selecting-channels
@krusche krusche modified the milestones: 7.6.5, 7.6.4 Oct 27, 2024
@krusche krusche changed the title Communication: Fix duplicate call of messages api when selecting a channel Development: Fix duplicate server calls for messages when selecting a channel Oct 27, 2024
@krusche krusche changed the title Development: Fix duplicate server calls for messages when selecting a channel Development: Fix duplicate server calls for messages when selecting a conversation Oct 27, 2024
@krusche krusche merged commit 27f4f60 into develop Oct 27, 2024
26 of 29 checks passed
@krusche krusche deleted the bugfix/communication/fix-thread-loading-twice-when-selecting-channels branch October 27, 2024 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client Pull requests that update TypeScript code. (Added Automatically!) small
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants