Skip to content

fix: Add job check to get correct linkage#235

Merged
adityachoudhari26 merged 1 commit intomainfrom
add-job-check-generating-chidlren
Nov 26, 2024
Merged

fix: Add job check to get correct linkage#235
adityachoudhari26 merged 1 commit intomainfrom
add-job-check-generating-chidlren

Conversation

@adityachoudhari26
Copy link
Copy Markdown
Member

@adityachoudhari26 adityachoudhari26 commented Nov 26, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced resource retrieval with optional job ID filtering for more precise job resource relationships.
  • Bug Fixes

    • Improved logic for querying parent and child nodes based on job context, ensuring accurate data retrieval.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Nov 26, 2024

Walkthrough

The pull request modifies the getNodeDataForResource function in packages/api/src/router/resources.ts to include an optional jobId parameter. This allows filtering of job resource relationships based on the provided job ID. The function's internal logic has been updated to incorporate this parameter in the query for parent job resource relationships. Additionally, the getNodesRecursivelyHelper function has been adjusted to pass the jobId when retrieving child nodes, enhancing the granularity of resource retrieval based on job identifiers.

Changes

File Change Summary
packages/api/src/router/resources.ts Updated getNodeDataForResource to include an optional jobId parameter and adjusted query logic. Updated getNodesRecursivelyHelper to pass jobId to getNodeDataForResource.

Possibly related PRs

  • fix: Use left join on resource to make it nullable #232: The changes in this PR also involve the getNodesRecursivelyHelper function in the same file, which is directly related to the modifications made in the main PR regarding the retrieval of relationships and the handling of job IDs.

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 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
Copy Markdown
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

🧹 Outside diff range and nitpick comments (1)
packages/api/src/router/resources.ts (1)

435-439: Consider handling undefined matchesJobId condition

The current implementation might pass undefined to the and() function when jobId is null. While this might work due to the isPresent filter elsewhere in the codebase, it would be more explicit to handle this case.

Consider this alternative:

  const matchesJobId =
    jobId == null ? undefined : eq(schema.jobResourceRelationship.jobId, jobId);
  const parent = await db.query.jobResourceRelationship.findFirst({
-   where: and(matchesIdentifier, matchesJobId),
+   where: matchesJobId ? and(matchesIdentifier, matchesJobId) : matchesIdentifier,
  });
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9d796d7 and be7f4f1.

📒 Files selected for processing (1)
  • packages/api/src/router/resources.ts (3 hunks)
🔇 Additional comments (3)
packages/api/src/router/resources.ts (3)

410-414: LGTM: Function signature updated correctly

The addition of the optional jobId parameter is well-typed and aligns with the PR objective.


528-528: LGTM: Correctly propagating job context

The update properly passes the job ID when retrieving child nodes, ensuring consistent filtering throughout the resource tree.


410-414: Verify all function calls are updated

Let's verify that all calls to getNodeDataForResource have been updated to handle the new parameter.

✅ Verification successful

All calls to getNodeDataForResource are properly updated

The verification shows two calls to getNodeDataForResource:

  • Line 528: Correctly passes db, r.resource.id, and r.jobId
  • Line 540: Correctly passes db and resourceId (jobId is optional parameter)

Both usages are consistent with the function signature which declares jobId as an optional parameter.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all calls to getNodeDataForResource
ast-grep --pattern 'getNodeDataForResource($$$)'

Length of output: 253

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