Skip to content

Disable filters for platform and project databases - Stat resources#11027

Merged
ChiragAgg5k merged 15 commits into1.8.xfrom
lohanidamodar-patch-2
Dec 29, 2025
Merged

Disable filters for platform and project databases - Stat resources#11027
ChiragAgg5k merged 15 commits into1.8.xfrom
lohanidamodar-patch-2

Conversation

@lohanidamodar
Copy link
Copy Markdown
Member

What does this PR do?

  • Disable filters for platform and project databases - Stat resources

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?

- Disable filters for platform and project databases - Stat resources
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Dec 28, 2025

📝 Walkthrough

Walkthrough

  • In src/Appwrite/Platform/Workers/StatsResources.php two direct calls were replaced with calls wrapped by skipFilters: countForDatabase($dbForProject, $region) is now invoked inside $dbForProject->skipFilters(fn () => $this->countForDatabase($dbForProject, $region), ['subQueryAttributes', 'subQueryIndexes']), and countForSitesAndFunctions($dbForProject, $region) is now invoked inside $dbForProject->skipFilters(fn () => $this->countForSitesAndFunctions($dbForProject, $region), ['subQueryVariables', 'subQueryProjectVariables']). Error handling and surrounding logic were not changed.
  • In src/Appwrite/Platform/Action.php the protected array $filters was modified: 'subQueryProjectVariables' was removed from the Project group and added to the Sites / Functions group, changing which filter set disables that sub-query.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Disable filters for platform and project databases - Stat resources' directly describes the main change: disabling filters in the StatsResources class and reorganizing filter configuration in Action.php.
Description check ✅ Passed The description mentions disabling filters for platform and project databases for Stat resources, which aligns with the changeset modifications to StatsResources.php and Action.php filter configurations.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch lohanidamodar-patch-2

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c463a9a and 5d92014.

📒 Files selected for processing (1)
  • src/Appwrite/Platform/Workers/StatsResources.php
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: abnegate
Repo: appwrite/appwrite PR: 10297
File: app/controllers/api/users.php:649-657
Timestamp: 2025-08-11T10:32:38.142Z
Learning: In Appwrite's utopia-php/database (version 0.77.* and later), the database layer internally handles filter separation for count operations. When using `$dbForProject->count()` within a `skipFilters` closure, there's no need to manually separate filter queries using `Query::groupByType($queries)['filters']` as the database handles this automatically.
Learnt from: abnegate
Repo: appwrite/appwrite PR: 10546
File: src/Appwrite/Platform/Workers/Migrations.php:144-148
Timestamp: 2025-10-23T08:06:38.889Z
Learning: In the Appwrite codebase, migration workers receive already-validated data from queued jobs. Query validation using Query::parseQueries() happens at the API endpoint level (with try-catch for QueryException) before jobs are queued, so workers in src/Appwrite/Platform/Workers/Migrations.php don't need redundant validation.
📚 Learning: 2025-08-11T10:32:38.142Z
Learnt from: abnegate
Repo: appwrite/appwrite PR: 10297
File: app/controllers/api/users.php:649-657
Timestamp: 2025-08-11T10:32:38.142Z
Learning: In Appwrite's utopia-php/database (version 0.77.* and later), the database layer internally handles filter separation for count operations. When using `$dbForProject->count()` within a `skipFilters` closure, there's no need to manually separate filter queries using `Query::groupByType($queries)['filters']` as the database handles this automatically.

Applied to files:

  • src/Appwrite/Platform/Workers/StatsResources.php
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: E2E Service Test (Sites)
  • GitHub Check: E2E Service Test (Migrations)
  • GitHub Check: E2E Service Test (Storage)
  • GitHub Check: E2E Service Test (FunctionsSchedule)
  • GitHub Check: E2E Service Test (Messaging)
  • GitHub Check: E2E Service Test (Proxy)
  • GitHub Check: E2E Service Test (Users)
  • GitHub Check: E2E Service Test (Tokens)
  • GitHub Check: E2E Service Test (Account)
  • GitHub Check: E2E Service Test (GraphQL)
  • GitHub Check: E2E Service Test (Functions)
  • GitHub Check: E2E Service Test (Databases/TablesDB)
  • GitHub Check: E2E Service Test (Avatars)
  • GitHub Check: E2E Service Test (Databases/Legacy)
  • GitHub Check: Unit Test
  • GitHub Check: E2E Service Test (Site Screenshots)
  • GitHub Check: E2E General Test
  • GitHub Check: E2E Service Test (Dev Keys)
  • GitHub Check: Benchmark
  • GitHub Check: scan
🔇 Additional comments (2)
src/Appwrite/Platform/Workers/StatsResources.php (2)

201-201: LGTM! Filter list correctly aligned with Action.php changes.

The skipFilters closure pattern is correctly applied, and the filter list ['subQueryVariables', 'subQueryProjectVariables'] appropriately matches the operations performed within countForSitesAndFunctions for sites, functions, and their deployments.

This aligns with the related change in Action.php that moved subQueryProjectVariables from the Project group to the Sites/Functions group.


195-195: LGTM! Scoped filter skipping correctly applied.

The skipFilters closure pattern properly addresses the previous concern about global filter state side effects. The filter lists are correctly chosen: ['subQueryAttributes', 'subQueryIndexes'] for database and collection counting operations, and ['subQueryVariables', 'subQueryProjectVariables'] for sites and functions operations, matching the filters triggered at the collection schema level.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 28, 2025

Security Scan Results for PR

Docker Image Scan Results

Package Version Vulnerability Severity
libpng 1.6.51-r0 CVE-2025-66293 HIGH
libpng-dev 1.6.51-r0 CVE-2025-66293 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

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1529357 and aa17eeb.

📒 Files selected for processing (1)
  • src/Appwrite/Platform/Workers/StatsResources.php
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: abnegate
Repo: appwrite/appwrite PR: 10297
File: app/controllers/api/users.php:649-657
Timestamp: 2025-08-11T10:32:38.142Z
Learning: In Appwrite's utopia-php/database (version 0.77.* and later), the database layer internally handles filter separation for count operations. When using `$dbForProject->count()` within a `skipFilters` closure, there's no need to manually separate filter queries using `Query::groupByType($queries)['filters']` as the database handles this automatically.
📚 Learning: 2025-08-11T10:32:38.142Z
Learnt from: abnegate
Repo: appwrite/appwrite PR: 10297
File: app/controllers/api/users.php:649-657
Timestamp: 2025-08-11T10:32:38.142Z
Learning: In Appwrite's utopia-php/database (version 0.77.* and later), the database layer internally handles filter separation for count operations. When using `$dbForProject->count()` within a `skipFilters` closure, there's no need to manually separate filter queries using `Query::groupByType($queries)['filters']` as the database handles this automatically.

Applied to files:

  • src/Appwrite/Platform/Workers/StatsResources.php
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: scan

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 28, 2025

✨ Benchmark results

  • Requests per second: 1,120
  • Requests with 200 status code: 201,642
  • P99 latency: 0.177037736

⚡ Benchmark Comparison

Metric This PR Latest version
RPS 1,120 1,213
200 201,642 218,378
P99 0.177037736 0.17130552

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

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 61c619f and 08f3022.

📒 Files selected for processing (1)
  • src/Appwrite/Platform/Workers/StatsResources.php
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: abnegate
Repo: appwrite/appwrite PR: 10297
File: app/controllers/api/users.php:649-657
Timestamp: 2025-08-11T10:32:38.142Z
Learning: In Appwrite's utopia-php/database (version 0.77.* and later), the database layer internally handles filter separation for count operations. When using `$dbForProject->count()` within a `skipFilters` closure, there's no need to manually separate filter queries using `Query::groupByType($queries)['filters']` as the database handles this automatically.
📚 Learning: 2025-08-11T10:32:38.142Z
Learnt from: abnegate
Repo: appwrite/appwrite PR: 10297
File: app/controllers/api/users.php:649-657
Timestamp: 2025-08-11T10:32:38.142Z
Learning: In Appwrite's utopia-php/database (version 0.77.* and later), the database layer internally handles filter separation for count operations. When using `$dbForProject->count()` within a `skipFilters` closure, there's no need to manually separate filter queries using `Query::groupByType($queries)['filters']` as the database handles this automatically.

Applied to files:

  • src/Appwrite/Platform/Workers/StatsResources.php
🪛 GitHub Actions: Linter
src/Appwrite/Platform/Workers/StatsResources.php

[error] 1-1: PSR-12 linting failed: 892 files, 1 style issue. no_whitespace_in_blank_lines (style issue in src/Appwrite/Platform/Workers/StatsResources.php).


[error] 1-1: Pint lint run failed. Command 'vendor/bin/pint --test --config pint.json' exited with code 1.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: E2E Service Test (FunctionsSchedule)
  • GitHub Check: E2E Service Test (Messaging)
  • GitHub Check: E2E Service Test (Sites)
  • GitHub Check: E2E Service Test (Projects)
  • GitHub Check: E2E Service Test (Avatars)
  • GitHub Check: E2E Service Test (Databases/Legacy)
  • GitHub Check: E2E Service Test (Databases/TablesDB)
  • GitHub Check: Benchmark
🔇 Additional comments (1)
src/Appwrite/Platform/Workers/StatsResources.php (1)

103-104: The review comment is based on incorrect code identification.

The code at lines 103-104 does not contain disableFilters() calls. Line 103 contains $this->disableSubqueries(); instead. A search of the entire file confirms there are no disableFilters() or enableFilters() calls anywhere in src/Appwrite/Platform/Workers/StatsResources.php. The concerns raised about global side effects on injected database instances do not apply to this code.

Likely an incorrect or invalid review comment.

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

♻️ Duplicate comments (1)
src/Appwrite/Platform/Workers/StatsResources.php (1)

102-102: Remove trailing whitespace from blank line.

Line 102 contains trailing whitespace, causing the PSR-12 linting failure (no_whitespace_in_blank_lines).

🔎 Proposed fix
-    
+
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9c8f565 and 126de78.

📒 Files selected for processing (2)
  • src/Appwrite/Platform/Action.php
  • src/Appwrite/Platform/Workers/StatsResources.php
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: abnegate
Repo: appwrite/appwrite PR: 10297
File: app/controllers/api/users.php:649-657
Timestamp: 2025-08-11T10:32:38.142Z
Learning: In Appwrite's utopia-php/database (version 0.77.* and later), the database layer internally handles filter separation for count operations. When using `$dbForProject->count()` within a `skipFilters` closure, there's no need to manually separate filter queries using `Query::groupByType($queries)['filters']` as the database handles this automatically.
Learnt from: abnegate
Repo: appwrite/appwrite PR: 10546
File: src/Appwrite/Platform/Workers/Migrations.php:144-148
Timestamp: 2025-10-23T08:06:38.889Z
Learning: In the Appwrite codebase, migration workers receive already-validated data from queued jobs. Query validation using Query::parseQueries() happens at the API endpoint level (with try-catch for QueryException) before jobs are queued, so workers in src/Appwrite/Platform/Workers/Migrations.php don't need redundant validation.
📚 Learning: 2025-08-11T10:32:38.142Z
Learnt from: abnegate
Repo: appwrite/appwrite PR: 10297
File: app/controllers/api/users.php:649-657
Timestamp: 2025-08-11T10:32:38.142Z
Learning: In Appwrite's utopia-php/database (version 0.77.* and later), the database layer internally handles filter separation for count operations. When using `$dbForProject->count()` within a `skipFilters` closure, there's no need to manually separate filter queries using `Query::groupByType($queries)['filters']` as the database handles this automatically.

Applied to files:

  • src/Appwrite/Platform/Workers/StatsResources.php
  • src/Appwrite/Platform/Action.php
📚 Learning: 2025-10-02T10:16:48.075Z
Learnt from: abnegate
Repo: appwrite/appwrite PR: 10023
File: src/Appwrite/Databases/TransactionState.php:174-219
Timestamp: 2025-10-02T10:16:48.075Z
Learning: In `src/Appwrite/Databases/TransactionState.php`, the `listDocuments` method intentionally applies queries only to the initial database fetch of committed documents. Transaction state changes (creates, updates, deletes) are then overlaid on top of the filtered committed set without re-evaluating the queries against the final merged result. This is the intended behavior for transaction-aware document listing.

Applied to files:

  • src/Appwrite/Platform/Action.php
🧬 Code graph analysis (1)
src/Appwrite/Platform/Workers/StatsResources.php (1)
src/Appwrite/Platform/Action.php (1)
  • disableSubqueries (110-127)
🪛 GitHub Actions: Linter
src/Appwrite/Platform/Workers/StatsResources.php

[error] 1-1: PSR-12: no_whitespace_in_blank_lines issue detected by Pint linter in StatsResources.php. Run 'vendor/bin/pint --write' to fix code style issues.

🪛 PHPMD (2.15.0)
src/Appwrite/Platform/Action.php

49-49: Avoid unused parameters such as '$filters'. (undefined)

(UnusedFormalParameter)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: E2E Service Test (Projects)
  • GitHub Check: E2E Service Test (Health)
  • GitHub Check: E2E Service Test (Account)
  • GitHub Check: E2E Service Test (Locale)
  • GitHub Check: E2E Service Test (VCS)
  • GitHub Check: E2E Service Test (Proxy)
  • GitHub Check: E2E Service Test (Databases/Legacy)
  • GitHub Check: E2E Service Test (Console)
  • GitHub Check: E2E Service Test (Avatars)
  • GitHub Check: E2E Service Test (Realtime)
  • GitHub Check: E2E Service Test (Messaging)
  • GitHub Check: E2E Service Test (FunctionsSchedule)
  • GitHub Check: E2E Service Test (Databases/TablesDB)
  • GitHub Check: E2E Service Test (GraphQL)
  • GitHub Check: E2E Service Test (Functions)
  • GitHub Check: E2E Service Test (Dev Keys)
  • GitHub Check: E2E Service Test (Site Screenshots)
  • GitHub Check: Unit Test
  • GitHub Check: E2E General Test
  • GitHub Check: scan
🔇 Additional comments (2)
src/Appwrite/Platform/Workers/StatsResources.php (2)

103-103: Verify necessity of disableSubqueries() call.

Based on the past discussion where you acknowledged that skipFilters might make disableSubqueries() unnecessary, this global filter modification is still present. The disableSubqueries() method adds global filters that affect all subsequent database operations in this worker, which differs from the scoped skipFilters() pattern used on Line 202.

Can you clarify:

  • Is this global subquery disabling intentional for all operations in this worker?
  • Or should specific operations use scoped skipFilters() instead, similar to Line 202?

202-202: Good use of scoped skipFilters pattern.

The scoped skipFilters() closure correctly ensures filters are automatically restored after the operation, preventing global side effects. This aligns with the pattern used elsewhere in the codebase.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/Appwrite/Platform/Workers/StatsResources.php (1)

103-204: Inconsistent application of skipFilters – other database operations remain unprotected.

Only the call to countForSitesAndFunctions (line 201) is wrapped with skipFilters, while all other database operations in the same method (lines 107-155) lack this protection. According to the PR title "Disable filters for platform and project databases - Stat resources", filters should be disabled for ALL database operations in this worker, not just one.

The following operations also need to be wrapped with skipFilters:

  • Lines 107-120: $dbForPlatform->count() operations for platforms, webhooks, keys, and domains
  • Lines 123-155: $dbForProject->count() operations for databases, buckets, users, teams, functions, messages, providers, topics, and targets
🔎 Example of applying skipFilters consistently
         try {

             $region = $project->getAttribute('region');

-            $platforms = $dbForPlatform->count('platforms', [
+            $platforms = $dbForPlatform->skipFilters(fn() => $dbForPlatform->count('platforms', [
                 Query::equal('projectInternalId', [$project->getSequence()])
-            ]);
+            ]), $this->filters);
-            $webhooks = $dbForPlatform->count('webhooks', [
+            $webhooks = $dbForPlatform->skipFilters(fn() => $dbForPlatform->count('webhooks', [
                 Query::equal('projectInternalId', [$project->getSequence()])
-            ]);
+            ]), $this->filters);

Apply this pattern to all remaining count() and sum() operations on both $dbForPlatform and $dbForProject throughout the method.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 472e2c2 and bd9f02b.

📒 Files selected for processing (2)
  • src/Appwrite/Platform/Action.php
  • src/Appwrite/Platform/Workers/StatsResources.php
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: abnegate
Repo: appwrite/appwrite PR: 10297
File: app/controllers/api/users.php:649-657
Timestamp: 2025-08-11T10:32:38.142Z
Learning: In Appwrite's utopia-php/database (version 0.77.* and later), the database layer internally handles filter separation for count operations. When using `$dbForProject->count()` within a `skipFilters` closure, there's no need to manually separate filter queries using `Query::groupByType($queries)['filters']` as the database handles this automatically.
📚 Learning: 2025-08-11T10:32:38.142Z
Learnt from: abnegate
Repo: appwrite/appwrite PR: 10297
File: app/controllers/api/users.php:649-657
Timestamp: 2025-08-11T10:32:38.142Z
Learning: In Appwrite's utopia-php/database (version 0.77.* and later), the database layer internally handles filter separation for count operations. When using `$dbForProject->count()` within a `skipFilters` closure, there's no need to manually separate filter queries using `Query::groupByType($queries)['filters']` as the database handles this automatically.

Applied to files:

  • src/Appwrite/Platform/Action.php
  • src/Appwrite/Platform/Workers/StatsResources.php
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: E2E Service Test (Realtime)
  • GitHub Check: E2E Service Test (FunctionsSchedule)
  • GitHub Check: E2E Service Test (VCS)
  • GitHub Check: E2E Service Test (Health)
  • GitHub Check: E2E Service Test (Messaging)
  • GitHub Check: E2E Service Test (Webhooks)
  • GitHub Check: E2E Service Test (Users)
  • GitHub Check: E2E Service Test (Functions)
  • GitHub Check: E2E Service Test (Account)
  • GitHub Check: E2E Service Test (Avatars)
  • GitHub Check: E2E Service Test (GraphQL)
  • GitHub Check: E2E Service Test (Tokens)
  • GitHub Check: E2E Service Test (Teams)
  • GitHub Check: E2E Service Test (Console)
  • GitHub Check: E2E Service Test (Locale)
  • GitHub Check: E2E Service Test (Site Screenshots)
  • GitHub Check: Unit Test
  • GitHub Check: E2E General Test
  • GitHub Check: E2E Service Test (Dev Keys)
  • GitHub Check: scan
🔇 Additional comments (1)
src/Appwrite/Platform/Action.php (1)

24-28: The reference to StatsResources.php line 201 is incorrect—this file does not exist in the codebase. Additionally, no code selectively applies filters by the comment grouping in the array. The disableSubqueries() method in Action.php either uses the entire $filters array or selectively uses filters by explicit name in configuration files, not by comment-based groups. The reorganization of subQueryProjectVariables from the Project group to the Sites/Functions group is safe and aligns with its actual usage (the varsProject field configuration in the projects collection).

Likely an incorrect or invalid review comment.

@ChiragAgg5k ChiragAgg5k merged commit ac137ce into 1.8.x Dec 29, 2025
71 of 72 checks passed
@ChiragAgg5k ChiragAgg5k deleted the lohanidamodar-patch-2 branch December 29, 2025 06:21
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