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

chore: duplicate the uploaded assets for duplicated page #6311

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

Conversation

NarayanBavisetti
Copy link
Collaborator

@NarayanBavisetti NarayanBavisetti commented Jan 3, 2025

Description

this pull request ensures assets are duplicated along with the page during duplication.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

References

Summary by CodeRabbit

  • New Features

    • Added ability to duplicate page assets and S3 objects when duplicating a page
    • Introduced new environment configuration for live base URL
    • Enhanced S3 storage with object copying functionality
  • Improvements

    • Implemented asynchronous background task for asset duplication
    • Added robust error handling for asset management processes

Copy link
Contributor

coderabbitai bot commented Jan 3, 2025

Walkthrough

This pull request introduces a new mechanism for handling asset duplication during page or entity copying. A new background task (copy_s3_objects) has been implemented to automatically copy S3 objects associated with duplicated pages. The changes span multiple files, adding functionality to extract, duplicate, and update asset references in HTML descriptions. A new S3 storage method for object copying and a live base URL configuration are also included, supporting the asset duplication workflow.

Changes

File Change Summary
apiserver/plane/app/views/page/base.py Added import and async task call to copy_s3_objects.delay() for page duplication
apiserver/plane/bgtasks/copy_s3_object.py New file with multiple utility functions for asset management and duplication
apiserver/plane/settings/common.py Added LIVE_BASE_URL environment variable configuration
apiserver/plane/settings/storage.py Added copy_object() method to S3Storage class for S3 object copying

Sequence Diagram

sequenceDiagram
    participant User
    participant PageDuplicateEndpoint
    participant CopyS3ObjectTask
    participant S3Storage
    
    User->>PageDuplicateEndpoint: Request page duplication
    PageDuplicateEndpoint->>CopyS3ObjectTask: Trigger copy_s3_objects.delay()
    CopyS3ObjectTask->>CopyS3ObjectTask: Extract asset IDs
    CopyS3ObjectTask->>S3Storage: Copy S3 objects
    CopyS3ObjectTask->>CopyS3ObjectTask: Update HTML descriptions
    CopyS3ObjectTask-->>PageDuplicateEndpoint: Return duplicated assets
Loading

Possibly related PRs

Suggested reviewers

  • pablohashescobar

Poem

🐰 Hopping through code with glee,
Duplicating assets, setting them free!
S3 objects dance, a magical sight,
Copying pages with rabbit-like might!
Async tasks spinning, a technological spree! 🚀


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 anywhere in the PR title to generate the title automatically.

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

🧹 Nitpick comments (3)
apiserver/plane/bgtasks/copy_s3_object.py (3)

34-40: Caution: swallowing exceptions can mask underlying errors.
This function returns an empty list if parsing fails, potentially hiding issues involving malformed HTML or BeautifulSoup usage. Consider logging the exception or re-raising it to facilitate troubleshooting.


62-78: Add request timeouts and handle unexpected responses.
Using a timeout parameter in requests.post(...) would help avoid indefinite waits if the external service is slow. Also consider handling unexpected response formats or status codes for enhanced resilience.


80-143: Handle concurrency and address line-length warnings.

  1. This Celery task can race with other tasks for the same entity. If multiple tasks try to copy assets concurrently, unexpected duplicates or data inconsistencies could appear. Consider gating tasks, or verifying if a task for the same entity is already in progress.
  2. Several lines exceed 88 characters (e.g., lines 85, 86, 105). Complying with line-length standards can improve readability and pass automated lint checks.

Below is a suggested way to split line 105 as an example:

-            destination_key = f"{workspace.id}/{uuid.uuid4().hex}-{original_asset.attributes.get('name')}"
+            asset_name = original_asset.attributes.get("name")
+            destination_key = f"{workspace.id}/{uuid.uuid4().hex}-{asset_name}"
🧰 Tools
🪛 Ruff (0.8.2)

85-85: Line too long (104 > 88)

(E501)


86-86: Line too long (101 > 88)

(E501)


105-105: Line too long (106 > 88)

(E501)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2622dd6 and 26763c4.

📒 Files selected for processing (4)
  • apiserver/plane/app/views/page/base.py (2 hunks)
  • apiserver/plane/bgtasks/copy_s3_object.py (1 hunks)
  • apiserver/plane/settings/common.py (1 hunks)
  • apiserver/plane/settings/storage.py (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Build and Lint on Pull Request
apiserver/plane/settings/common.py

[error] 176-176: Line too long (90 > 88 characters)

🪛 Ruff (0.8.2)
apiserver/plane/bgtasks/copy_s3_object.py

85-85: Line too long (104 > 88)

(E501)


86-86: Line too long (101 > 88)

(E501)


105-105: Line too long (106 > 88)

(E501)

🔇 Additional comments (7)
apiserver/plane/bgtasks/copy_s3_object.py (3)

17-31: Consider raising an error or logging more information for unrecognized entity types.
By returning an empty dictionary if entity_type is not found, the caller may not detect that an unsupported type was used. Incorporating at least a warning log or raising an explicit exception could help pinpoint issues early.


42-52: Replacement logic looks correct; watch out for partial matches.
Currently, the logic replaces src attributes only when there's an exact match. Ensure that unintended partial matches (e.g., query parameters) don't occur, or handle them separately if needed.


54-59: Consider concurrency or versioning for shared entities.
When update_description is called by multiple tasks in parallel, the last update might overwrite earlier changes. If concurrency is a concern, consider implementing an optimistic locking strategy or a revision check.

apiserver/plane/settings/storage.py (1)

155-167: Copy logic is well-structured; consider verifying source object existence.
The copy_object method uses a try-except block to handle ClientError, but you could also verify that the source object exists before attempting the copy. This would allow for more specific error messages and reduce reliance on exception-handling as flow control.

apiserver/plane/settings/common.py (1)

339-340: Verify that the LIVE_BASE_URL is properly set for all environments.
Ensure that this new environment variable is set in each deployment environment, or handle cases when it’s absent to prevent failures in external service calls.

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

42-42: Import statement is correct.
Bringing in copy_s3_objects here is in line with the asynchronous task usage.


590-599: Ensure error handling for the asynchronous duplication task.
The copy_s3_objects.delay(...) call does not track success or failure once initiated. Consider providing a callback or updating relevant logs/fields so you can track and alert the user if asset copying fails.

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.

1 participant