Skip to content

Comments

[WEB-1980] feat: user recent visited entities#5211

Merged
sriramveeraghanta merged 6 commits intopreviewfrom
feat/recent-visited
Aug 19, 2024
Merged

[WEB-1980] feat: user recent visited entities#5211
sriramveeraghanta merged 6 commits intopreviewfrom
feat/recent-visited

Conversation

@NarayanBavisetti
Copy link
Collaborator

@NarayanBavisetti NarayanBavisetti commented Jul 23, 2024

Issue Link: WEB-1980

  • New Features

    • Enhanced tracking of user interactions across various entities, including cycles, issues, modules, pages, and projects. Users' recent visits are now recorded asynchronously to improve analytics.
  • Bug Fixes

    • Addressed minor formatting issues in import statements for improved code clarity.
  • Chores

    • Added new background task functionality to manage user visit records, ensuring efficient data handling and maintaining a cap on stored records.

Summary by CodeRabbit

  • New Features

    • Introduced tracking of recently visited tasks, issues, modules, pages, and projects to enhance user engagement analytics.
    • Added functionality to retrieve issue views with expanded parameters for more detailed interaction tracking.
  • Bug Fixes

    • Corrected import formatting for improved code cleanliness without affecting functionality.
  • Documentation

    • Updated comments and function summaries to reflect new features and task behavior related to user interactions.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 23, 2024

Walkthrough

The recent updates enhance user interaction tracking across various views in the application. By introducing asynchronous task calls to the recent_visited_task.delay function, the system now logs user visits to cycles, issues, modules, pages, and projects. This improvement allows for better analytics and insights into user behavior, significantly enriching the user experience and enabling data management.

Changes

Files Change Summary
apiserver/plane/app/views/cycle/base.py Added asynchronous logging of user visits to cycles in the retrieve method.
apiserver/plane/app/views/issue/base.py Integrated user visit logging in get, list, and retrieve methods for issues.
apiserver/plane/app/views/module/base.py Enhanced retrieve method to log user visits for modules.
apiserver/plane/app/views/page/base.py Updated retrieve method to track visits to pages.
apiserver/plane/app/views/project/base.py Added logging of user visits in the retrieve method for projects.
apiserver/plane/app/views/view/base.py Introduced two retrieve methods to log user interactions more specifically, including one with project_id.
apiserver/plane/bgtasks/recent_visited_task.py New file created with a Celery task to manage user recent visit records.
apiserver/plane/db/models/__init__.py Minor formatting change in import statements; no functional alterations made.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant API
    participant TaskQueue
    participant Database

    User->>API: Request to view a cycle/issue/module/page/project
    API->>Database: Retrieve entity data
    Database-->>API: Return entity information
    API->>TaskQueue: recent_visited_task.delay(...)
    TaskQueue->>Database: Log user visit
    Database-->>TaskQueue: Confirm visit logged
    TaskQueue-->>API: Acknowledge logging
    API-->>User: Return entity data
Loading

🐇 Hop along, oh code so bright,
With logs of visits, what a sight!
Each click and scroll, a tale to tell,
Enhancing user joy, oh so well!
Adventures tracked in the digital glade,
Let's celebrate this charming upgrade!
🐇


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
Contributor

@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: 11

Outside diff range, codebase verification and nitpick comments (3)
apiserver/plane/bgtasks/recent_visited_task.py (1)

1-10: Organize imports for better readability.

Group imports into standard library, third-party, and local imports.

# Python imports
from django.utils import timezone

# Third party imports
from celery import shared_task

# Module imports
from plane.db.models import UserRecentVisit, Workspace
from plane.utils.exception_logger import log_exception
apiserver/plane/app/views/view/base.py (2)

113-128: Ensure consistency in retrieve method parameters.

The retrieve method in apiserver/plane/app/views/view/base.py has inconsistent parameters. There are two definitions:

  • (self, request, slug, pk)
  • (self, request, slug, project_id, pk)

Please verify and ensure that project_id is correctly handled and consistent across the method definitions.

  • apiserver/plane/app/views/view/base.py
Analysis chain

Ensure consistency in retrieve method parameters.

The retrieve method parameters should be consistent with the class's purpose. Verify that project_id is correctly handled.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the consistency of `retrieve` method parameters.

# Test: Search for the `retrieve` method definitions. Expect: Consistent parameters.
rg --type python 'def retrieve'

Length of output: 64


Script:

#!/bin/bash
# Description: Verify the consistency of `retrieve` method parameters.

# Test: Search for the `retrieve` method definitions. Expect: Consistent parameters.
rg 'def retrieve' --glob '*.py' -A 5

Length of output: 7480


393-408: Ensure consistency in retrieve method parameters.

The IssueViewFavoriteViewSet class in apiserver/plane/app/views/view/base.py contains two retrieve methods with different parameters. This inconsistency needs to be addressed to ensure clarity and proper usage.

  • def retrieve(self, request, slug, pk)
  • def retrieve(self, request, slug, project_id, pk)

Please review and refactor these methods to maintain consistency.

Analysis chain

Ensure consistency in retrieve method parameters.

The retrieve method parameters should be consistent with the class's purpose. Verify that project_id is correctly handled.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the consistency of `retrieve` method parameters.

# Test: Search for the `retrieve` method definitions. Expect: Consistent parameters.
rg --type python 'def retrieve'

Length of output: 64


Script:

#!/bin/bash
# Description: Verify the consistency of `retrieve` method parameters.

# Test: Search for the `retrieve` method definitions. Expect: Consistent parameters.
rg 'def retrieve'

Length of output: 1513


Script:

#!/bin/bash
# Description: Verify the context of `retrieve` method parameters in `apiserver/plane/app/views/view/base.py`.

# Test: Search for the class definitions and usages of `retrieve` methods in the specified file.
rg -A 10 'class ' apiserver/plane/app/views/view/base.py
rg -A 10 'def retrieve' apiserver/plane/app/views/view/base.py

Length of output: 2318

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a8b2bcc and 47d52c2.

Files selected for processing (8)
  • apiserver/plane/app/views/cycle/base.py (2 hunks)
  • apiserver/plane/app/views/issue/base.py (4 hunks)
  • apiserver/plane/app/views/module/base.py (2 hunks)
  • apiserver/plane/app/views/page/base.py (2 hunks)
  • apiserver/plane/app/views/project/base.py (2 hunks)
  • apiserver/plane/app/views/view/base.py (4 hunks)
  • apiserver/plane/bgtasks/recent_visited_task.py (1 hunks)
  • apiserver/plane/db/models/init.py (1 hunks)
Additional context used
Ruff
apiserver/plane/db/models/__init__.py

114-114: .recent_visit.UserRecentVisit imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)

Additional comments not posted (5)
apiserver/plane/db/models/__init__.py (1)

114-114: Verify the necessity of the import.

Ensure that UserRecentVisit is used within the module or add it to __all__ if it is intended to be publicly accessible.

Verification successful

The import of UserRecentVisit is necessary as it is used in the codebase, specifically in the recent_visited_task.py file and a migration file. However, it is not included in the __all__ list in apiserver/plane/db/models/__init__.py. If UserRecentVisit is intended to be publicly accessible, consider adding it to the __all__ list.

  • File: apiserver/plane/db/models/__init__.py
  • Lines: Add UserRecentVisit to __all__ if it is meant to be publicly accessible.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `UserRecentVisit` in the module.

# Test: Search for the usage of `UserRecentVisit`. Expect: At least one usage or add to `__all__`.
rg --type python 'UserRecentVisit'

Length of output: 65


Script:

#!/bin/bash
# Description: Verify the usage of `UserRecentVisit` in the module and check if it is included in `__all__`.

# Search for the usage of `UserRecentVisit` in the codebase.
rg 'UserRecentVisit'

# Check if `UserRecentVisit` is included in the `__all__` list in the `__init__.py` file.
rg '__all__' apiserver/plane/db/models/__init__.py -A 5

Length of output: 880

Tools
Ruff

114-114: .recent_visit.UserRecentVisit imported but unused; consider removing, adding to __all__, or using a redundant alias

(F401)

apiserver/plane/app/views/view/base.py (2)

118-124: Ensure proper handling of asynchronous tasks.

Verify that recent_visited_task.delay is correctly called and handled.

Verification successful

Ensure proper handling of asynchronous tasks.

The recent_visited_task.delay function is correctly called and handled across multiple files. The function is defined in apiserver/plane/bgtasks/recent_visited_task.py and is properly imported where used.

  • Files with usage:
    • apiserver/plane/app/views/view/base.py
    • apiserver/plane/app/views/project/base.py
    • apiserver/plane/app/views/page/base.py
    • apiserver/plane/app/views/issue/base.py
    • apiserver/plane/app/views/module/base.py
    • apiserver/plane/app/views/cycle/base.py
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `recent_visited_task.delay`.

# Test: Search for the usage of `recent_visited_task.delay`. Expect: Correct usage.
rg --type python 'recent_visited_task.delay'

Length of output: 75


Script:

#!/bin/bash
# Description: Verify the usage of `recent_visited_task.delay`.

# Search for the usage of `recent_visited_task.delay` in Python files.
rg 'recent_visited_task.delay' --glob '*.py' -A 5

# Search for the definition of `recent_visited_task`.
rg 'recent_visited_task' --glob '*.py' -A 5

# Search for the import of `recent_visited_task`.
rg 'import recent_visited_task' --glob '*.py' -A 5

Length of output: 13423


398-404: Ensure proper handling of asynchronous tasks.

Verify that recent_visited_task.delay is correctly called and handled.

apiserver/plane/app/views/module/base.py (1)

663-669: Ensure proper error handling for the asynchronous task.

The recent_visited_task.delay call logs user visits asynchronously. Ensure that any potential errors in the task do not affect the main functionality of the retrieve method.

Is there a mechanism in place to handle potential errors from recent_visited_task.delay?

apiserver/plane/app/views/cycle/base.py (1)

1037-1043: Ensure proper error handling for the asynchronous task.

The recent_visited_task.delay call logs user visits asynchronously. Ensure that any potential errors in the task do not affect the main functionality of the retrieve method.

Is there a mechanism in place to handle potential errors from recent_visited_task.delay?

Copy link
Contributor

@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: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 47d52c2 and 1eef6e1.

Files selected for processing (6)
  • apiserver/plane/app/views/cycle/base.py (2 hunks)
  • apiserver/plane/app/views/issue/base.py (4 hunks)
  • apiserver/plane/app/views/module/base.py (2 hunks)
  • apiserver/plane/app/views/page/base.py (2 hunks)
  • apiserver/plane/app/views/project/base.py (2 hunks)
  • apiserver/plane/app/views/view/base.py (4 hunks)
Additional comments not posted (6)
apiserver/plane/app/views/page/base.py (1)

225-231: Integration of asynchronous task looks good.

The recent_visited_task.delay() call is correctly placed to track page visits asynchronously. Ensure that error handling is implemented as suggested in the existing comment.

apiserver/plane/app/views/issue/base.py (3)

131-137: Integration of asynchronous task looks good.

The recent_visited_task.delay() call is correctly placed to track issue list retrievals asynchronously. Ensure that error handling is implemented as suggested in the existing comment.


259-265: Integration of asynchronous task looks good.

The recent_visited_task.delay() call is correctly placed to track issue list retrievals asynchronously. Ensure that error handling is implemented as suggested in the existing comment.


503-509: Integration of asynchronous task looks good.

The recent_visited_task.delay() call is correctly placed to track issue retrievals asynchronously. Ensure that error handling is implemented as suggested in the existing comment.

apiserver/plane/app/views/project/base.py (1)

268-274: Integration of asynchronous task looks good.

The recent_visited_task.delay() call is correctly placed to track project retrievals asynchronously. Ensure that error handling is implemented as suggested in the existing comment.

apiserver/plane/app/views/cycle/base.py (1)

1032-1038: Verify the handling of asynchronous task inputs.

Ensure that the recent_visited_task function correctly handles the inputs and operates efficiently. Consider potential impacts on performance and user experience, especially in high-traffic scenarios.

Verification successful

The recent_visited_task function is implemented and used correctly.

The function is defined as a Celery task and handles the parameters as expected. It is imported and utilized across multiple modules, including the one under review. The task's implementation appears to align with its intended purpose of tracking recent visits. No issues were found regarding its definition or usage.

  • Location of definition: apiserver/plane/bgtasks/recent_visited_task.py
  • Usage in various modules: Confirmed through imports and task execution.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of the `recent_visited_task` function to ensure it handles inputs correctly and efficiently.

# Test: Search for the function implementation. Expect: Correct handling of parameters and efficient execution.
ast-grep --lang python --pattern $'def recent_visited_task(slug, entity_name, entity_identifier, user_id, project_id):\n  $$$'

Length of output: 126


Script:

#!/bin/bash
# Description: Search for the definition or import of `recent_visited_task` in the codebase.

# Search for the function definition with any parameter signature.
ast-grep --lang python --pattern 'def recent_visited_task($$$):\n  $$$'

# Search for import statements that might import `recent_visited_task`.
rg 'import .+recent_visited_task' --context 2

Length of output: 121


Script:

#!/bin/bash
# Description: Search for any usage of `recent_visited_task` in the codebase to gather more context.

# Search for any usage of `recent_visited_task`.
rg 'recent_visited_task' --context 5

Length of output: 12727

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants