Skip to content

Conversation

@adityachoudhari26
Copy link
Contributor

@adityachoudhari26 adityachoudhari26 commented May 8, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Improved accuracy in updating and matching release targets, ensuring only affected targets are processed.
  • Performance
    • Enhanced efficiency by reducing unnecessary data queries and focusing updates on relevant release targets.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 8, 2025

Walkthrough

The code updates the logic in the compute-policy-target-release-target-selector worker. It modifies how release targets are queried, locked, deleted, and inserted within a transaction. The selection and dispatching of release targets for evaluation now use a more targeted approach, focusing only on affected release targets.

Changes

File(s) Change Summary
apps/event-worker/src/workers/compute-policy-target-release-target-selector.ts Updated imports to include inArray. Changed the query to fetch policyTarget without eager-loading policy. Removed extraction of workspaceId. Added a SELECT ... FOR UPDATE NOWAIT lock on relevant computedPolicyTargetReleaseTarget rows. Modified deletion to return deleted rows. Calculated unmatched and newReleaseTargets sets. Inserted new release targets only if present, using onConflictDoNothing. Queried and dispatched jobs only for affected release targets using inArray.

Sequence Diagram(s)

sequenceDiagram
    participant Worker
    participant DB
    participant JobDispatcher

    Worker->>DB: Fetch policyTarget (no policy join)
    Worker->>DB: Lock computedPolicyTargetReleaseTarget rows (FOR UPDATE NOWAIT)
    Worker->>DB: Delete obsolete computedPolicyTargetReleaseTarget rows (returning deleted)
    Worker->>DB: Insert new computedPolicyTargetReleaseTarget rows (onConflictDoNothing)
    Worker->>DB: Query releaseTarget rows by affected IDs (using inArray)
    Worker->>JobDispatcher: Dispatch evaluation jobs for affected releaseTargets
Loading

Possibly related PRs

  • fix: actually delete unmatched release targets #525: Both PRs modify the logic around handling unmatched or obsolete release targets within transactional updates, specifically focusing on identifying and deleting release targets that no longer match the current criteria before inserting new ones.
  • perf: only add new release targets to evaluate queue #544: The main PR and the retrieved PR both modify the handling of release target sets within transactions and adjust the logic for dispatching evaluation jobs based on newly created or affected release targets, indicating a related change in how release targets are processed and queued for evaluation.

Suggested reviewers

  • jsbroks

Poem

A hop, a skip, through targets anew,
Locking and matching, the queries flew.
Unmatched are gone, the new ones stay,
Jobs dispatched in a rabbit's way.
With every transaction, the garden grows—
Release targets pruned, as the logic flows! 🐇

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f52edbc and 5f9306b.

📒 Files selected for processing (1)
  • apps/event-worker/src/workers/compute-policy-target-release-target-selector.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/event-worker/src/workers/compute-policy-target-release-target-selector.ts
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Typecheck
  • GitHub Check: Lint
  • GitHub Check: build (linux/amd64)
✨ 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.
    • 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.

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.

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

🧹 Nitpick comments (1)
apps/event-worker/src/workers/compute-policy-target-release-target-selector.ts (1)

74-82: Avoid SELECT * when acquiring locks – fetch only the minimal columns needed

The locking query currently pulls all columns from both tables even though the result set is immediately discarded. This unnecessarily increases I/O and memory pressure inside the transaction.

-        await tx.execute(
-          sql`
-            SELECT * from ${schema.computedPolicyTargetReleaseTarget}
-            INNER JOIN ${schema.releaseTarget} ON ${eq(schema.releaseTarget.id, schema.computedPolicyTargetReleaseTarget.releaseTargetId)}
-            WHERE ${eq(schema.computedPolicyTargetReleaseTarget.policyTargetId, policyTarget.id)}
-            FOR UPDATE NOWAIT
-          `,
-        );
+        await tx.execute(
+          sql`
+            /* row-lock only the PKs we care about */
+            SELECT ${schema.computedPolicyTargetReleaseTarget.id}
+            FROM ${schema.computedPolicyTargetReleaseTarget}
+            INNER JOIN ${schema.releaseTarget}
+              ON ${eq(
+                schema.releaseTarget.id,
+                schema.computedPolicyTargetReleaseTarget.releaseTargetId,
+              )}
+            WHERE ${eq(
+              schema.computedPolicyTargetReleaseTarget.policyTargetId,
+              policyTarget.id,
+            )}
+            FOR UPDATE NOWAIT
+          `,
+        );

Smaller result sets shorten lock-hold time and keep the transaction lighter.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 492faa9 and f52edbc.

📒 Files selected for processing (1)
  • apps/event-worker/src/workers/compute-policy-target-release-target-selector.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{ts,tsx}`: **Note on Error Handling:** Avoid strict enforcement of try/catch blocks. Code may use early returns, Promise chains (.then().catch()), or other patterns for error...

**/*.{ts,tsx}: Note on Error Handling:
Avoid strict enforcement of try/catch blocks. Code may use early returns, Promise chains (.then().catch()), or other patterns for error handling. These are acceptable as long as they maintain clarity and predictability.

  • apps/event-worker/src/workers/compute-policy-target-release-target-selector.ts
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Typecheck
  • GitHub Check: Lint
  • GitHub Check: build (linux/amd64)

@adityachoudhari26 adityachoudhari26 merged commit b5a2f3d into main May 8, 2025
5 of 6 checks passed
@adityachoudhari26 adityachoudhari26 deleted the optimize-compute-policy-target branch May 8, 2025 06:41
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