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

[WIP] Optimized jobs page and IAM information retrival #8156

Closed
wants to merge 9 commits into from

Conversation

bsekachev
Copy link
Member

@bsekachev bsekachev commented Jul 12, 2024

Motivation and context

In a task with 19 jobs (actually it worked O(number of jobs))
Before:
image

After: ( still O(number of jobs), but already better):
image

How has this been tested?

Checklist

  • I submit my changes into the develop branch
  • I have created a changelog fragment
  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • I have linked related issues (see GitHub docs)
  • I have increased versions of npm packages if it is necessary
    (cvat-canvas,
    cvat-core,
    cvat-data and
    cvat-ui)

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.

Summary by CodeRabbit

  • Performance Improvements

    • Enhanced efficiency in retrieving subsets and dimensions from tasks, leading to faster data processing.
  • Bug Fixes

    • Improved handling of empty cases when fetching task attributes.
  • Backend Enhancements

    • Optimized database queries in ProjectViewSet, TaskViewSet, and JobViewSet with a select_related clause for better performance and reduced database hits.
  • Code Simplification

    • Simplified the get_organization function, making it more straightforward and removing unnecessary exception handling.

Copy link
Contributor

coderabbitai bot commented Jul 12, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The updates enhance the efficiency and accuracy of data retrieval in serializers and views, streamline query performance by leveraging select_related, and simplify permission logic in the get_organization function by directly accessing attributes. These modifications aim to improve performance and maintainability across the system.

Changes

Files Change Summary
cvat/apps/engine/serializers.py Updated the to_representation method to use generator expressions for fetching subsets and dimensions, improving efficiency.
cvat/apps/engine/views.py Added conditions and select_related clauses to preview methods in ProjectViewSet and TaskViewSet for optimized querying. Enhanced JobViewSet queryset with expanded select_related fields.
cvat/apps/iam/permissions.py Simplified get_organization function by directly returning the organization attribute, removing exception handling logic.

Poem

In the code where tasks once tread,
Efficiency now softly spreads.
Queries swift, permissions light,
Serialization shines so bright.
With each change, in lines so clear,
Performance leaps, let's give a cheer! 🚀


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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 54e857d and e181724.

Files selected for processing (3)
  • cvat/apps/engine/serializers.py (1 hunks)
  • cvat/apps/engine/views.py (4 hunks)
  • cvat/apps/iam/permissions.py (2 hunks)
Additional comments not posted (5)
cvat/apps/iam/permissions.py (1)

42-42: Simplification of get_organization function is effective but needs verification.

The new implementation is more straightforward and reduces potential error points. However, ensure that the simplification does not overlook any edge cases that the previous logic handled.

Verification successful

Simplification of get_organization function is verified and does not introduce any errors.

The new implementation is straightforward and effectively handles the necessary cases without overlooking any edge cases.

  • The get_organization function correctly returns the organization attribute or None.
  • The usage of get_organization in get_iam_context is appropriate and functions as expected.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `get_organization` function to ensure the new implementation does not introduce any errors.

# Test: Search for the function usage. Expect: No breaking changes due to simplification.
rg --type python -A 5 $'get_organization'

Length of output: 71


Script:

#!/bin/bash
# Description: Verify the usage of `get_organization` function to ensure the new implementation does not introduce any errors.

# Test: Search for the function usage. Expect: No breaking changes due to simplification.
rg -A 5 'get_organization'

Length of output: 2897


Script:

#!/bin/bash
# Description: Verify the detailed context of `get_organization` function usage in `cvat/apps/iam/permissions.py`.

# Test: Search for the function usage with more surrounding lines for context.
rg 'get_organization' -A 10 -B 10 cvat/apps/iam/permissions.py

Length of output: 1426

cvat/apps/engine/serializers.py (1)

1347-1352: Optimize generator expressions and handle empty cases gracefully.

The generator expressions for subsets and dimensions improve efficiency by avoiding the creation of intermediate lists. However, there are a few points to consider:

  1. The generator expressions are executed twice, which might result in a performance hit. Consider storing the results in variables if the task list is large.
  2. The use of next for dimensions is appropriate for handling empty cases gracefully.
  3. Ensure the task_subsets set handles empty strings correctly.
+        subsets = (task.subset for task in instance.tasks.all())
+        dimensions = (task.dimension for task in instance.tasks.all())
+        task_subsets = set(subsets)
+        task_subsets.discard('')
+        response['task_subsets'] = list(task_subsets)
+        response['dimension'] = next(dimensions, None)
cvat/apps/engine/views.py (3)

292-293: LGTM! The conditional block optimizes query performance.

The added condition in the get_queryset method for the preview action filters the queryset based on the kwargs, which should enhance performance for this specific action.


630-630: LGTM! The change ensures the most recent task is used for the preview.

The preview method now selects the first task related to the project using select_related for the data field and orders by -id, ensuring that the most recent task is used for the preview image.


869-870: LGTM! The conditional block optimizes query performance.

The added condition in the get_queryset method for the preview action filters the queryset based on the kwargs and uses select_related for the data field to optimize query performance.

@bsekachev bsekachev changed the title Otimized jobs page and IAM information retrival [WIP] Otimized jobs page and IAM information retrival Jul 12, 2024
@bsekachev bsekachev changed the title [WIP] Otimized jobs page and IAM information retrival [WIP] Optimized jobs page and IAM information retrival Jul 12, 2024
Copy link

sonarcloud bot commented Jul 12, 2024

@bsekachev
Copy link
Member Author

Will start from scratch

@bsekachev bsekachev closed this Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant