Skip to content

Fix: Rule querying improt#9915

Merged
Meldiron merged 3 commits into1.7.xfrom
1.7.x-logging
May 27, 2025
Merged

Fix: Rule querying improt#9915
Meldiron merged 3 commits into1.7.xfrom
1.7.x-logging

Conversation

@Meldiron
Copy link
Copy Markdown
Contributor

@Meldiron Meldiron commented May 27, 2025

What does this PR do?

  • Fix queries not applied
  • Use utopia Db lib looping method

Test Plan

(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work. Screenshots may also be helpful.)

Related PRs and Issues

  • (Related PR or issue)

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

Summary by CodeRabbit

  • Refactor
    • Streamlined rule updates by replacing an internal helper method with direct database iteration, ensuring more explicit query filtering and authorization handling.
  • Bug Fixes
    • Improved accuracy of rule updates by consistently applying project-specific filters during deployment updates.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented May 27, 2025

Walkthrough

The changes remove the listRules protected method from multiple classes and replace its usage with direct database iteration using foreach or forEach methods. All affected code paths now explicitly add a filter for projectInternalId and wrap database operations with authorization skipping, streamlining rule updates during deployment processes.

Changes

File(s) Change Summary
src/Appwrite/Platform/Modules/Compute/Base.php
src/Appwrite/Platform/Modules/Functions/Workers/Builds.php
Removed the listRules protected method; updated logic to use direct database iteration with explicit filters.
src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php
src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php
Replaced listRules usage with direct $dbForPlatform->foreach() and added a projectInternalId filter.
All affected files Replaced Appwrite\Query imports with Utopia\Database\Query where necessary.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Database
    participant Authorization

    Caller->>Database: foreach('rules', [Query::equal('projectInternalId', ...)], callback)
    activate Authorization
    Note right of Authorization: Authorization::skip() wraps the operation
    Database-->>Caller: For each rule document
    Caller->>Database: Update rule with new deployment IDs (Authorization::skip())
Loading

Suggested reviewers

  • christyjacob4

Poem

In the warren of code, some rules took a hop,
The old listRules method, we gave it a stop.
Now with foreach, we bound and we leap,
Updating deployments in one tidy sweep.
With project IDs checked and permissions in tow,
The database bunnies are ready to go!
🐇✨

✨ 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.

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 Author

@Meldiron Meldiron left a comment

Choose a reason for hiding this comment

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

LGTM

@github-actions
Copy link
Copy Markdown

Security Scan Results for PR

Docker Image Scan Results

Package Version Vulnerability Severity
binutils 2.42-r0 CVE-2025-0840 HIGH
libexpat 2.6.4-r0 CVE-2024-8176 HIGH
libxml2 2.12.7-r0 CVE-2024-56171 HIGH
libxml2 2.12.7-r0 CVE-2025-24928 HIGH
libxml2 2.12.7-r0 CVE-2025-27113 HIGH
libxml2 2.12.7-r0 CVE-2025-32414 HIGH
libxml2 2.12.7-r0 CVE-2025-32415 HIGH
sqlite-libs 3.45.3-r1 CVE-2025-29087 HIGH
xz 5.6.2-r0 CVE-2025-31115 HIGH
xz-libs 5.6.2-r0 CVE-2025-31115 HIGH
golang.org/x/crypto v0.31.0 CVE-2025-22869 HIGH

Source Code Scan Results

🎉 No vulnerabilities found!

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

🔭 Outside diff range comments (2)
src/Appwrite/Platform/Modules/Functions/Workers/Builds.php (2)

1083-1091: ⚠️ Potential issue

Critical: Remove duplicate query condition.

The projectInternalId query condition is added twice (lines 1084 and 1090). This duplication could cause database query errors or unexpected filtering behavior.

Remove the duplicate query condition:

         $queries = [
             Query::equal("projectInternalId", [$project->getInternalId()]),
             Query::equal("type", ["deployment"]),
             Query::equal("deploymentResourceInternalId", [$resource->getInternalId()]),
             Query::equal('deploymentResourceType', ['function']),
             Query::equal('trigger', ['manual']),
             Query::equal('deploymentVcsProviderBranch', ['']),
-            Query::equal("projectInternalId", [$project->getInternalId()])
         ];

1109-1117: ⚠️ Potential issue

Critical: Remove duplicate query condition.

The projectInternalId query condition is duplicated again (lines 1110 and 1116).

Remove the duplicate query condition:

         $queries = [
             Query::equal("projectInternalId", [$project->getInternalId()]),
             Query::equal("type", ["deployment"]),
             Query::equal("deploymentResourceInternalId", [$resource->getInternalId()]),
             Query::equal('deploymentResourceType', ['site']),
             Query::equal('trigger', ['manual']),
             Query::equal('deploymentVcsProviderBranch', ['']),
-            Query::equal("projectInternalId", [$project->getInternalId()])
         ];
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 64cea46 and 501d29f.

📒 Files selected for processing (4)
  • src/Appwrite/Platform/Modules/Compute/Base.php (0 hunks)
  • src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php (2 hunks)
  • src/Appwrite/Platform/Modules/Functions/Workers/Builds.php (3 hunks)
  • src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php (2 hunks)
💤 Files with no reviewable changes (1)
  • src/Appwrite/Platform/Modules/Compute/Base.php
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: scan
🔇 Additional comments (5)
src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php (2)

14-15: LGTM! Import updated correctly.

The import change from Appwrite\Query to Utopia\Database\Query aligns with the broader refactoring to use the Utopia database library's query methods.


106-120: Good implementation of direct database iteration with proper scoping.

The changes correctly:

  • Add projectInternalId filter to ensure rules are scoped to the current project
  • Replace the removed listRules method with direct $dbForPlatform->foreach() iteration
  • Properly wrap database operations with Authorization::skip() for system-level updates
src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php (1)

14-14: Consistent implementation across modules.

The changes mirror those in the Functions module, maintaining consistency in how rules are queried and updated across different resource types (functions and sites).

Also applies to: 98-112

src/Appwrite/Platform/Modules/Functions/Workers/Builds.php (2)

1094-1100: LGTM! Proper implementation of direct database iteration.

The replacement of listRules with $dbForPlatform->forEach() is correctly implemented with appropriate query filters and authorization skipping.


1119-1124: Consistent implementation of database iteration.

Both sites-related rule update operations correctly use $dbForPlatform->foreach() with proper query filters, maintaining consistency with the refactoring pattern.

Also applies to: 1176-1181

Comment on lines +1166 to +1174
$queries = [
Query::equal("projectInternalId", [$project->getInternalId()]),
Query::equal("type", ["deployment"]),
Query::equal("deploymentResourceInternalId", [$resource->getInternalId()]),
Query::equal('deploymentResourceType', ['site']),
Query::equal("deploymentVcsProviderBranch", [$branchName]),
Query::equal("trigger", ['manual']),
], $dbForPlatform, function (Document $rule) use ($dbForPlatform, $deployment) {
Query::equal("projectInternalId", [$project->getInternalId()])
];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical: Remove duplicate query condition.

The projectInternalId query condition is duplicated once more (lines 1167 and 1173).

Remove the duplicate query condition:

                     $queries = [
                         Query::equal("projectInternalId", [$project->getInternalId()]),
                         Query::equal("type", ["deployment"]),
                         Query::equal("deploymentResourceInternalId", [$resource->getInternalId()]),
                         Query::equal('deploymentResourceType', ['site']),
                         Query::equal("deploymentVcsProviderBranch", [$branchName]),
                         Query::equal("trigger", ['manual']),
-                        Query::equal("projectInternalId", [$project->getInternalId()])
                     ];
📝 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
$queries = [
Query::equal("projectInternalId", [$project->getInternalId()]),
Query::equal("type", ["deployment"]),
Query::equal("deploymentResourceInternalId", [$resource->getInternalId()]),
Query::equal('deploymentResourceType', ['site']),
Query::equal("deploymentVcsProviderBranch", [$branchName]),
Query::equal("trigger", ['manual']),
], $dbForPlatform, function (Document $rule) use ($dbForPlatform, $deployment) {
Query::equal("projectInternalId", [$project->getInternalId()])
];
$queries = [
Query::equal("projectInternalId", [$project->getInternalId()]),
Query::equal("type", ["deployment"]),
Query::equal("deploymentResourceInternalId", [$resource->getInternalId()]),
Query::equal('deploymentResourceType', ['site']),
Query::equal("deploymentVcsProviderBranch", [$branchName]),
Query::equal("trigger", ['manual']),
];
🤖 Prompt for AI Agents
In src/Appwrite/Platform/Modules/Functions/Workers/Builds.php around lines 1166
to 1174, the query condition for "projectInternalId" is duplicated. Remove the
redundant Query::equal("projectInternalId", [$project->getInternalId()]) entry
to keep only one instance of this condition in the $queries array.

@Meldiron Meldiron merged commit 340211e into 1.7.x May 27, 2025
35 of 37 checks passed
@github-actions
Copy link
Copy Markdown

✨ Benchmark results

  • Requests per second: 987
  • Requests with 200 status code: 177,640
  • P99 latency: 0.185618013

⚡ Benchmark Comparison

Metric This PR Latest version
RPS 987 1,135
200 177,640 204,383
P99 0.185618013 0.164302132

@coderabbitai coderabbitai bot mentioned this pull request May 29, 2025
2 tasks
@coderabbitai coderabbitai bot mentioned this pull request Jun 12, 2025
2 tasks
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