Skip to content

Conversation

killagu
Copy link
Contributor

@killagu killagu commented May 31, 2025

Summary by CodeRabbit

  • New Features
    • Added support for a new task property to prevent certain tasks from being merged when waiting, providing more granular control over task handling.
  • Bug Fixes
    • Improved logic for task merging to consider both task type and a new optional flag, ensuring correct behavior for historical task compensation scenarios.
  • Tests
    • Introduced new tests to verify the updated task merging logic and the effect of the new property.
  • Chores
    • Limited the number of items returned per request when fetching platform-specific binaries to improve data retrieval efficiency.

Copy link
Contributor

coderabbitai bot commented May 31, 2025

Walkthrough

This update introduces a shouldNotMerge flag to task data, changes task merging logic from a static to an instance-based method, and limits S3 binary list requests to 100 results per call. It also adds targeted tests for the new task merging behavior.

Changes

Files/Paths Change Summary
app/common/adapter/binary/PuppeteerBinary.ts Appends max-keys=100 to the S3 request URL to limit binary list results per request.
app/core/entity/Task.ts Adds shouldNotMerge to TaskBaseData; converts merge logic to instance method considering flag.
app/core/service/TaskService.ts Updates merge check to use the new instance method on Task.
test/core/entity/Task.test.ts Adds tests for needMergeWhenWaiting, covering both flag-enabled and default behaviors.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant TaskService
    participant Task

    Client->>TaskService: createTask(data)
    TaskService->>Task: Instantiate Task with data
    TaskService->>Task: call needMergeWhenWaiting()
    alt data.shouldNotMerge is true
        Task-->>TaskService: return false
    else type is SyncBinary or SyncPackage
        Task-->>TaskService: return true
    else
        Task-->>TaskService: return false
    end
    TaskService-->>Client: Proceed based on merge decision
Loading

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • fengmk2
  • elrrrrrrr

Poem

A flag for merging, a limit for keys,
Tasks now decide with a gentle breeze.
S3 fetches just a hundred at a time,
While tests ensure all works just fine.
Hopping forward, code refined—
🐇✨ Merged with care, by rabbit design!


📜 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 fb51a40 and 5dc0ff6.

📒 Files selected for processing (1)
  • app/core/service/TaskService.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/core/service/TaskService.ts
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Trag Review
  • GitHub Check: test-mysql57-fs-nfs (24, ubuntu-latest)
  • GitHub Check: test-postgresql-fs-nfs (24, ubuntu-latest)
  • GitHub Check: test-postgresql-fs-nfs (22, ubuntu-latest)
  • GitHub Check: test-postgresql-fs-nfs (20, ubuntu-latest)
  • GitHub Check: test-mysql57-fs-nfs (20, ubuntu-latest)
  • GitHub Check: test-mysql57-fs-nfs (22, ubuntu-latest)
  • GitHub Check: test-mysql57-s3-nfs (20, ubuntu-latest)
  • GitHub Check: test-mysql57-s3-nfs (22, ubuntu-latest)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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 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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cb3768c and fb51a40.

📒 Files selected for processing (4)
  • app/common/adapter/binary/PuppeteerBinary.ts (1 hunks)
  • app/core/entity/Task.ts (2 hunks)
  • app/core/service/TaskService.ts (2 hunks)
  • test/core/entity/Task.test.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
test/core/entity/Task.test.ts (1)
app/core/entity/Task.ts (1)
  • Task (102-321)
🪛 GitHub Actions: Node.js CI
app/core/service/TaskService.ts

[error] 7-8: ESLint (no-duplicate-imports): '../entity/Task.js' import is duplicated. Merge the duplicated import into a single import statement.


[error] 7-8: eslint-plugin-import (no-duplicates): Modules should not be imported multiple times in the same file. Merge these imports into a single import statement.


[error] 8-8: typescript-eslint (no-import-type-side-effects): TypeScript will only remove the inline type specifiers which leaves behind a side effect import at runtime. Convert this to a top-level type qualifier to properly remove the entire import.

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: test-postgresql-fs-nfs (24, ubuntu-latest)
  • GitHub Check: test-postgresql-fs-nfs (22, ubuntu-latest)
  • GitHub Check: test-postgresql-fs-nfs (20, ubuntu-latest)
🔇 Additional comments (5)
app/common/adapter/binary/PuppeteerBinary.ts (1)

59-59: LGTM! Good performance optimization.

Adding the max-keys=100 parameter to limit S3 results per request is a sensible approach to prevent memory issues and improve performance, especially given the existing iteration limit mentioned in the comments.

test/core/entity/Task.test.ts (1)

1-18: LGTM! Well-structured tests for the new functionality.

The test cases properly validate the new needMergeWhenWaiting() instance method behavior:

  • Correctly tests that shouldNotMerge: true prevents merging
  • Verifies default behavior for sync binary tasks
  • Good use of the existing createSyncBinary factory method
app/core/service/TaskService.ts (1)

33-33: LGTM! Correct transition to instance method.

The change from the static method Task.needMergeWhenWaiting(task.type) to the instance method task.needMergeWhenWaiting() correctly implements the new task merging logic that considers the shouldNotMerge flag.

app/core/entity/Task.ts (2)

19-19: LGTM! Well-designed flag for task merging control.

The optional shouldNotMerge flag provides a clean way to control task merging behavior, particularly useful for historical task compensation scenarios as mentioned in the comments.


272-280: LGTM! Correct implementation of instance-based merging logic.

The transition from a static method to an instance method is appropriate here since the decision now depends on task-specific data (shouldNotMerge flag). The implementation correctly:

  1. Prioritizes the shouldNotMerge flag to prevent merging when needed
  2. Falls back to the existing type-based logic for SyncBinary and SyncPackage tasks
  3. Includes clear comments explaining the use case for historical task compensation

Comment on lines 7 to 8
import type { Task} from '../entity/Task.js';
import { type CreateSyncPackageTaskData } from '../entity/Task.js';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix the duplicate imports and import structure.

The ESLint errors indicate issues with the import statements:

  1. Task is being imported twice (duplicate imports)
  2. The type-only import syntax is causing side effect issues

Apply this diff to fix the import issues:

-import type { Task} from '../entity/Task.js';
-import { type CreateSyncPackageTaskData } from '../entity/Task.js';
+import { Task, type CreateSyncPackageTaskData } from '../entity/Task.js';
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import type { Task} from '../entity/Task.js';
import { type CreateSyncPackageTaskData } from '../entity/Task.js';
import { Task, type CreateSyncPackageTaskData } from '../entity/Task.js';
🧰 Tools
🪛 GitHub Actions: Node.js CI

[error] 7-8: ESLint (no-duplicate-imports): '../entity/Task.js' import is duplicated. Merge the duplicated import into a single import statement.


[error] 7-8: eslint-plugin-import (no-duplicates): Modules should not be imported multiple times in the same file. Merge these imports into a single import statement.


[error] 8-8: typescript-eslint (no-import-type-side-effects): TypeScript will only remove the inline type specifiers which leaves behind a side effect import at runtime. Convert this to a top-level type qualifier to properly remove the entire import.

🤖 Prompt for AI Agents
In app/core/service/TaskService.ts around lines 7 to 8, there are duplicate
imports of Task and inconsistent type-only import syntax causing ESLint errors.
Consolidate the imports by combining Task and CreateSyncPackageTaskData into a
single type-only import statement from '../entity/Task.js' to avoid duplication
and side effect issues.

Copy link

trag-bot bot commented May 31, 2025

Pull request summary

  • Added a max-keys parameter to the S3 request URL in PuppeteerBinary.ts to limit the number of keys returned.
  • Introduced an optional shouldNotMerge property in the TaskBaseData interface to control task merging behavior.
  • Updated the needMergeWhenWaiting method in the Task class to check the shouldNotMerge property before deciding on task merging.
  • Refactored the task merging logic in TaskService.ts to utilize the instance method needMergeWhenWaiting instead of the static method.
  • Created unit tests for the needMergeWhenWaiting method to verify the new merging logic based on the shouldNotMerge property.

Copy link

codecov bot commented May 31, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.34%. Comparing base (54e3335) to head (5dc0ff6).
Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff            @@
##           master     #807    +/-   ##
========================================
  Coverage   95.33%   95.34%            
========================================
  Files         196      196            
  Lines       23666    23673     +7     
  Branches     2165     1937   -228     
========================================
+ Hits        22563    22570     +7     
  Misses       1103     1103            

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@elrrrrrrr elrrrrrrr merged commit 490dce3 into master May 31, 2025
14 checks passed
@elrrrrrrr elrrrrrrr deleted the feat/shouldNotMerge branch May 31, 2025 11:04
fengmk2 pushed a commit that referenced this pull request May 31, 2025
[skip ci]

## [4.7.0](v4.6.3...v4.7.0) (2025-05-31)

### Features

* add shouldNotMerge for task data for skip task merge ([#807](#807)) ([490dce3](490dce3))
fengmk2 pushed a commit that referenced this pull request May 31, 2025
[skip ci]

## [4.7.0](v4.6.3...v4.7.0) (2025-05-31)

### Features

* add shouldNotMerge for task data for skip task merge ([#807](#807)) ([490dce3](490dce3))

### Bug Fixes

* order binary by date ([#808](#808)) ([12aa425](12aa425))
fengmk2 pushed a commit that referenced this pull request Jun 9, 2025
[skip ci]

## [4.7.0](v4.6.3...v4.7.0) (2025-06-09)

### Features

* add shouldNotMerge for task data for skip task merge ([#807](#807)) ([490dce3](490dce3))

### Bug Fixes

* content type check ([#809](#809)) ([b8c7c06](b8c7c06)), closes [#693](#693)
* order binary by date ([#808](#808)) ([12aa425](12aa425))
fengmk2 pushed a commit that referenced this pull request Jun 10, 2025
[skip ci]

## [4.7.0](v4.6.3...v4.7.0) (2025-06-10)

### Features

* add shouldNotMerge for task data for skip task merge ([#807](#807)) ([490dce3](490dce3))

### Bug Fixes

* content type check ([#809](#809)) ([b8c7c06](b8c7c06)), closes [#693](#693)
* order binary by date ([#808](#808)) ([12aa425](12aa425))
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.

2 participants