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: add sync jobs for issue_version and issue_description_version tables #6199

Merged
merged 7 commits into from
Dec 13, 2024

Conversation

gurusainath
Copy link
Collaborator

@gurusainath gurusainath commented Dec 13, 2024

Description

Added synchronization jobs for issue_version and issue_description_version tables. These jobs ensure data consistency by syncing information across the relevant tables.

Type of Change

  • Feature (non-breaking change which adds functionality)

Summary by CodeRabbit

  • New Features
    • Introduced batch processing for synchronizing issue description and version records.
    • Added management commands to facilitate the creation of issue description and version records through user input.
  • Bug Fixes
    • Enhanced error handling during issue processing and version creation.
  • Documentation
    • Updated documentation for new management commands and their usage.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ gurusainath
❌ sainath


sainath seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Contributor

coderabbitai bot commented Dec 13, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The changes introduce new functionalities for synchronizing issue descriptions and versions in a Django application using Celery tasks. Two new files, issue_description_version_sync.py and issue_version_sync.py, define tasks for processing issues in batches, creating corresponding records in the database. Additionally, two management commands are added to facilitate the execution of these tasks from the command line, allowing users to specify batch parameters for asynchronous processing.

Changes

File Change Summary
apiserver/plane/bgtasks/issue_description_version_sync.py Added functionality for synchronizing issue description versions, including tasks sync_issue_description_version and schedule_issue_description_version.
`apiserver/plane/bgtasks/issue_version_sync.py Implemented functionalities for managing issue versions, including tasks sync_issue_version and schedule_issue_version.
apiserver/plane/db/management/commands/sync_issue_description_version.py Introduced a management command to create IssueDescriptionVersion records, prompting for batch_size and batch_countdown.
apiserver/plane/db/management/commands/sync_issue_version.py Introduced a management command to create IssueVersion records, prompting for batch_size and batch_countdown.

Possibly related PRs

Suggested reviewers

  • Pablo Hash Escobar
  • Sriram Veeraghanta

Poem

In the burrow deep, where tasks align,
New versions hop, oh how they shine!
With batches set and countdowns near,
Issue tales unfold, bring us cheer!
From description to version, they dance and play,
In the garden of code, they brighten the day! 🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3d8da7b and 0c6d2e2.

📒 Files selected for processing (2)
  • apiserver/plane/bgtasks/issue_description_version_sync.py (1 hunks)
  • apiserver/plane/bgtasks/issue_version_sync.py (1 hunks)

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. (Experiment)
  • @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: 8

🧹 Outside diff range and nitpick comments (6)
apiserver/plane/db/migrations/0087_remove_issueversion_description_and_more.py (1)

38-104: Adjust lines exceeding the maximum line length

Several lines exceed the maximum line length of 88 characters, as indicated by the static analysis tool. Consider wrapping these lines to improve code readability and comply with PEP 8 style guidelines.

For example, in line 38:

- field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='versions', to='db.issueactivity'),
+ field=models.ForeignKey(
+     null=True,
+     on_delete=django.db.models.deletion.SET_NULL,
+     related_name='versions',
+     to='db.issueactivity'
+ ),

Apply similar adjustments to other lines exceeding the maximum length.

🧰 Tools
🪛 Ruff (0.8.2)

38-38: Line too long (141 > 88)

(E501)


58-58: Line too long (141 > 88)

(E501)


63-63: Line too long (99 > 88)

(E501)


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

(E501)


65-65: Line too long (103 > 88)

(E501)


66-66: Line too long (140 > 88)

(E501)


74-74: Line too long (94 > 88)

(E501)


75-75: Line too long (200 > 88)

(E501)


76-76: Line too long (144 > 88)

(E501)


77-77: Line too long (206 > 88)

(E501)


78-78: Line too long (138 > 88)

(E501)


90-90: Line too long (99 > 88)

(E501)


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

(E501)


92-92: Line too long (103 > 88)

(E501)


93-93: Line too long (140 > 88)

(E501)


98-98: Line too long (91 > 88)

(E501)


99-99: Line too long (200 > 88)

(E501)


100-100: Line too long (142 > 88)

(E501)


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

(E501)


102-102: Line too long (143 > 88)

(E501)


103-103: Line too long (206 > 88)

(E501)


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

(E501)

apiserver/plane/bgtasks/issue_version_sync.py (1)

69-85: Refactor get_owner_id to avoid code duplication

The get_owner_id function is duplicated in both issue_version_sync.py and issue_description_version_sync.py. Consider moving this function to a shared utility module to promote code reusability and maintainability.

apiserver/plane/db/management/commands/sync_issue_version.py (1)

8-10: Enhance command documentation

The help text should provide more details about the expected input formats and their purpose.

Consider expanding the help text:

 class Command(BaseCommand):
-    help = "Creates IssueVersion records for existing Issues in batches"
+    help = """
+    Creates IssueVersion records for existing Issues in batches.
+    
+    Required inputs:
+    - batch_size: Positive integer specifying how many issues to process per batch
+    - batch_countdown: Non-negative integer specifying delay (in seconds) between batches
+    """
apiserver/plane/db/models/sticky.py (2)

18-19: Add color format validation

The color fields should validate hex color codes or predefined color names.

Consider adding a validator:

import re
from django.core.validators import RegexValidator

color_validator = RegexValidator(
    re.compile('^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$'),
    'Enter a valid hex color code (e.g. #FF0000 or #F00)',
    'invalid_color'
)

Then apply it to the fields:

-    color = models.CharField(max_length=255, blank=True, null=True)
-    background_color = models.CharField(max_length=255, blank=True, null=True)
+    color = models.CharField(max_length=7, blank=True, null=True, validators=[color_validator])
+    background_color = models.CharField(max_length=7, blank=True, null=True, validators=[color_validator])

12-15: Review storage strategy for multiple description formats

The model stores the description in multiple formats (JSON, HTML, stripped text, binary) which could lead to storage inefficiency and consistency issues.

Consider:

  1. Using computed properties instead of stored fields where possible
  2. Implementing signals to automatically update derived fields
  3. Documenting the purpose of each format, especially the binary field
  4. Adding integrity checks to ensure consistency between formats

Example implementation:

from django.db.models.signals import pre_save
from django.dispatch import receiver
import html2text

@receiver(pre_save, sender=Sticky)
def update_description_formats(sender, instance, **kwargs):
    if instance.description_html:
        # Strip HTML to get plain text
        h = html2text.HTML2Text()
        h.ignore_links = True
        instance.description_stripped = h.handle(instance.description_html).strip()
apiserver/plane/db/models/user.py (1)

29-35: Add documentation to explain the mobile onboarding differences.

Please add a docstring to explain why the mobile onboarding steps differ from the default onboarding (specifically, why 'workspace_invite' is omitted).

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a8140a5 and 3d8da7b.

📒 Files selected for processing (9)
  • apiserver/plane/bgtasks/issue_description_version_sync.py (1 hunks)
  • apiserver/plane/bgtasks/issue_version_sync.py (1 hunks)
  • apiserver/plane/db/management/commands/sync_issue_description_version.py (1 hunks)
  • apiserver/plane/db/management/commands/sync_issue_version.py (1 hunks)
  • apiserver/plane/db/migrations/0087_remove_issueversion_description_and_more.py (1 hunks)
  • apiserver/plane/db/models/__init__.py (2 hunks)
  • apiserver/plane/db/models/issue.py (4 hunks)
  • apiserver/plane/db/models/sticky.py (1 hunks)
  • apiserver/plane/db/models/user.py (2 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
apiserver/plane/db/migrations/0087_remove_issueversion_description_and_more.py

38-38: Line too long (141 > 88)

(E501)


58-58: Line too long (141 > 88)

(E501)


63-63: Line too long (99 > 88)

(E501)


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

(E501)


65-65: Line too long (103 > 88)

(E501)


66-66: Line too long (140 > 88)

(E501)


74-74: Line too long (94 > 88)

(E501)


75-75: Line too long (200 > 88)

(E501)


76-76: Line too long (144 > 88)

(E501)


77-77: Line too long (206 > 88)

(E501)


78-78: Line too long (138 > 88)

(E501)


90-90: Line too long (99 > 88)

(E501)


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

(E501)


92-92: Line too long (103 > 88)

(E501)


93-93: Line too long (140 > 88)

(E501)


98-98: Line too long (91 > 88)

(E501)


99-99: Line too long (200 > 88)

(E501)


100-100: Line too long (142 > 88)

(E501)


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

(E501)


102-102: Line too long (143 > 88)

(E501)


103-103: Line too long (206 > 88)

(E501)


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

(E501)

apiserver/plane/db/models/issue.py

18-18: .base.BaseModel imported but unused

Remove unused import: .base.BaseModel

(F401)

🔇 Additional comments (10)
apiserver/plane/bgtasks/issue_description_version_sync.py (3)

16-32: LGTM: get_owner_id function is properly implemented

The get_owner_id function correctly determines the owner of an issue by prioritizing updated_by_id, then created_by_id, and finally falling back to a project admin if necessary.


34-116: LGTM: sync_issue_description_version function is well-structured

The sync_issue_description_version function efficiently processes issues in batches, creates IssueDescriptionVersion records, and schedules subsequent batches when necessary. Error handling and transaction management are appropriately implemented.


118-122: LGTM: schedule_issue_description_version function correctly schedules tasks

The schedule_issue_description_version function accurately triggers the sync_issue_description_version task with the specified parameters.

apiserver/plane/db/migrations/0087_remove_issueversion_description_and_more.py (1)

18-112: LGTM: Migration script correctly alters the database schema

The migration script appropriately removes obsolete fields, adds new fields, and creates new models. The operations are well-defined and align with the intended database schema changes.

🧰 Tools
🪛 Ruff (0.8.2)

38-38: Line too long (141 > 88)

(E501)


58-58: Line too long (141 > 88)

(E501)


63-63: Line too long (99 > 88)

(E501)


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

(E501)


65-65: Line too long (103 > 88)

(E501)


66-66: Line too long (140 > 88)

(E501)


74-74: Line too long (94 > 88)

(E501)


75-75: Line too long (200 > 88)

(E501)


76-76: Line too long (144 > 88)

(E501)


77-77: Line too long (206 > 88)

(E501)


78-78: Line too long (138 > 88)

(E501)


90-90: Line too long (99 > 88)

(E501)


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

(E501)


92-92: Line too long (103 > 88)

(E501)


93-93: Line too long (140 > 88)

(E501)


98-98: Line too long (91 > 88)

(E501)


99-99: Line too long (200 > 88)

(E501)


100-100: Line too long (142 > 88)

(E501)


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

(E501)


102-102: Line too long (143 > 88)

(E501)


103-103: Line too long (206 > 88)

(E501)


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

(E501)

apiserver/plane/bgtasks/issue_version_sync.py (3)

28-67: LGTM: issue_task function properly logs issue versions

The issue_task function correctly identifies changes in issues and logs versions accordingly. The logic for updating existing versions or creating new ones is sound.


87-142: LGTM: get_related_data function efficiently retrieves related data

The get_related_data function effectively gathers related records such as cycle issues, assignees, labels, modules, and activities, optimizing data retrieval for batch processing.


193-247: LGTM: sync_issue_version function handles batch processing effectively

The sync_issue_version function processes issues in batches, creates IssueVersion records, and schedules subsequent tasks appropriately. Error handling and transaction management are properly implemented.

apiserver/plane/db/models/issue.py (1)

Line range hint 671-793: LGTM: Updates to IssueVersion and addition of IssueDescriptionVersion

The modifications to the IssueVersion class and the introduction of the IssueDescriptionVersion class are well-structured. The fields and methods align with the requirements for tracking issue versions and descriptions.

apiserver/plane/db/models/sticky.py (1)

15-15: Verify security implications of BinaryField

The description_binary field could pose security risks if not properly handled.

Let's check for any potential security issues in the codebase:

✅ Verification successful

BinaryField implementation appears secure with proper handling

The implementation shows appropriate security measures:

  • Binary data is properly streamed using StreamingHttpResponse with correct content-type
  • Base64 encoding/decoding is used for data transfer
  • Access control checks are in place before data retrieval
  • No direct binary data exposure in serializers
  • Data is handled through proper Django model fields and controlled endpoints
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for BinaryField usage and potential security risks

# Check for direct binary field access in views
echo "Checking views for binary field access..."
rg -l "description_binary" --type py | grep "views"

# Check for proper content-type handling in responses
echo "Checking response handling..."
rg -A 5 "description_binary" --type py | grep -B 2 -A 2 "HttpResponse"

# Look for file upload handling
echo "Checking file upload handling..."
rg -l "multipart/form-data" --type py

Length of output: 469


Script:

#!/bin/bash
# Let's examine the specific usage of description_binary in views

# Check the implementation in issue.py
echo "Checking issue.py implementation:"
rg -B 5 -A 10 "description_binary" apiserver/plane/space/views/issue.py

# Check the implementation in base.py
echo "Checking base.py implementation:"
rg -B 5 -A 10 "description_binary" apiserver/plane/app/views/page/base.py

# Check for any serializer handling of this field
echo "Checking serializers:"
rg -B 2 -A 2 "description_binary" --type py | grep -B 2 -A 2 "serializers"

# Check for any validation or sanitization
echo "Checking for validation:"
rg -B 2 -A 2 "description_binary" --type py | grep -B 2 -A 2 "clean|validate"

Length of output: 3148

apiserver/plane/db/models/__init__.py (1)

44-45: LGTM! Import statements are properly organized.

The new imports for IssueVersion, IssueDescriptionVersion, and Sticky are correctly placed and maintain the file's organization.

Also applies to: 82-83

apiserver/plane/bgtasks/issue_description_version_sync.py Outdated Show resolved Hide resolved
apiserver/plane/bgtasks/issue_version_sync.py Outdated Show resolved Hide resolved
apiserver/plane/bgtasks/issue_version_sync.py Outdated Show resolved Hide resolved
apiserver/plane/db/models/issue.py Outdated Show resolved Hide resolved
apiserver/plane/db/models/sticky.py Outdated Show resolved Hide resolved
apiserver/plane/db/models/user.py Outdated Show resolved Hide resolved
@sriramveeraghanta sriramveeraghanta merged commit df6a80e into preview Dec 13, 2024
10 of 14 checks passed
@sriramveeraghanta sriramveeraghanta deleted the chore_issue_version_sync_jobs branch December 13, 2024 12:18
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.

4 participants