Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Sync 1.6.x #9778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 17, 2025
Merged

Sync 1.6.x #9778

merged 5 commits into from
May 17, 2025

Conversation

abnegate
Copy link
Member

@abnegate abnegate commented May 17, 2025

What does this PR do?

(Provide a description of what this PR does and why it's needed.)

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

  • Bug Fixes
    • Removed support for GIF files as accepted input and output types.
  • Refactor
    • Improved database controller error handling and streamlined document fetching.
    • Simplified project collection deletion logic for better maintainability.
    • Centralized cache key generation for API requests.
    • Updated device resource initialization to use updated telemetry device imports.
    • Simplified database exception handling in general error processing.
  • New Features
    • Added a method for generating stable cache identifiers for requests.
  • Chores
    • Renamed resource for local device telemetry.
    • Cleaned up unused resources and imports in worker initialization scripts.

Copy link

coderabbitai bot commented May 17, 2025

Walkthrough

The changes update configuration files to remove GIF support, refactor exception and cache handling, simplify device resource initialization, and improve project deletion logic. A new method for cache key generation is introduced. Several resources and telemetry dependencies are renamed or adjusted, and exception handling is streamlined in controllers.

Changes

File(s) Change Summary
app/config/storage/inputs.php, app/config/storage/outputs.php Removed GIF file extension and MIME type from accepted input and output file types.
app/controllers/api/databases.php Refactored database document retrieval by removing authorization skips, enhanced exception handling including relationship exceptions, removed unused dependencies, improved error handling, adjusted code style, and updated cache purging calls.
app/controllers/general.php Simplified database exception handling by removing multiple specific exception cases; retained only Authorization and Timeout exceptions with minor adjustments.
app/controllers/shared/api.php Replaced manual cache key generation with calls to the new cacheIdentifier() method on the Request object for cache retrieval and storage.
app/init/resources.php Removed trailing blank line after resource definition; no functional changes.
app/worker.php Updated device resource registrations to instantiate aliased telemetry device class (TelemetryDevice) instead of the previous import; telemetry resource registration unchanged.
src/Appwrite/Platform/Workers/Deletes.php Refactored project collection deletion logic to iterate over metadata documents directly instead of using a manual loop with collection listing and limits.
src/Appwrite/Utopia/Request.php Added a new public method cacheIdentifier() that generates a stable, unique cache key string for GET requests based on sorted parameters and URI.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API_Controller
    participant Request
    participant Cache

    Client->>API_Controller: Send GET request
    API_Controller->>Request: Call cacheIdentifier()
    Request-->>API_Controller: Return cache key
    API_Controller->>Cache: Check for cached response
    alt Cache hit
        Cache-->>API_Controller: Return cached response
        API_Controller-->>Client: Respond with cached data
    else Cache miss
        API_Controller->>Client: Process and return fresh data
        API_Controller->>Cache: Store response using cacheIdentifier()
    end
Loading

Poem

Hopping through code, a rabbit’s delight,
GIFs have vanished, cache keys made right.
Exceptions now simpler, devices renamed,
Project deletions no longer chained.
With every commit, the garden grows neat—
Another code patch, another treat!
🐇✨


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between a96f770 and a484566.

📒 Files selected for processing (1)
  • app/init/resources.php (0 hunks)
💤 Files with no reviewable changes (1)
  • app/init/resources.php
⏰ Context from checks skipped due to timeout of 90000ms (19)
  • GitHub Check: E2E Service Test (Teams)
  • GitHub Check: E2E Service Test (Webhooks)
  • GitHub Check: E2E Service Test (Storage)
  • GitHub Check: E2E Service Test (Sites)
  • GitHub Check: E2E Service Test (Tokens)
  • GitHub Check: E2E Service Test (Projects)
  • GitHub Check: E2E Service Test (Realtime)
  • GitHub Check: E2E Service Test (Functions)
  • GitHub Check: E2E Service Test (FunctionsSchedule)
  • GitHub Check: E2E Service Test (Console)
  • GitHub Check: E2E Service Test (GraphQL)
  • GitHub Check: E2E Service Test (Account)
  • GitHub Check: Benchmark
  • GitHub Check: E2E Shared Mode Service Test (Dev Keys) (Shared V2)
  • GitHub Check: E2E Service Test (Dev Keys)
  • GitHub Check: E2E Shared Mode Service Test (Dev Keys) (Shared V1)
  • GitHub Check: Unit Test
  • GitHub Check: E2E General Test
  • GitHub Check: scan
✨ 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
Member

@ItzNotABug ItzNotABug left a comment

Choose a reason for hiding this comment

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

one comment

Copy link

github-actions bot commented May 17, 2025

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

@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: 4

🔭 Outside diff range comments (2)
app/controllers/api/databases.php (2)

279-286: ⚠️ Potential issue

Incorrect conditional – misplaced parentheses break the type check

getAttribute(('type') !== $type) evaluates the boolean result of the comparison and uses it as the attribute key, so the logic is never executed the way you expect.
Same issue for the filter check a few lines below.

-    if ($attribute->getAttribute(('type') !== $type)) {
+    if ($attribute->getAttribute('type') !== $type) {
...
-    if ($attribute->getAttribute('type') === Database::VAR_STRING && $attribute->getAttribute(('filter') !== $filter)) {
+    if (
+        $attribute->getAttribute('type') === Database::VAR_STRING &&
+        $attribute->getAttribute('filter') !== $filter
+    ) {

Leaving it as-is will always pass the if-condition and can lead to invalid attribute updates at runtime.


295-304: 🛠️ Refactor suggestion

Parameter shadowing hides semantic meaning

Overwriting $collectionId with a fully-qualified internal path makes the variable name lie about its contents and increases cognitive load. It also risks accidental use of the wrong identifier further down.

-    $collectionId =  'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId();
+    $collectionPath = 'database_' . $database->getInternalId() . '_collection_' . $collection->getInternalId();
...
-                collection: $collectionId,
+                collection: $collectionPath,

Consider renaming to $collectionPath (or similar) to keep the original $collectionId intact.

🧹 Nitpick comments (6)
src/Appwrite/Utopia/Request.php (1)

224-235: Cache key could be made more collision-resistant & nested-array friendly

The overall idea to centralise the cache-key logic is 👍, but two implementation details are worth another look:

  1. ksort() only sorts the top-level keys.
    A request like ?filters[a]=1&filters[b]=2 vs ?filters[b]=2&filters[a]=1 will still yield two different cache identifiers because the nested array order is preserved by serialize().
    A quick recursive sort prevents accidental cache misses:
+/**
+ * Recursively sort array keys to ensure deterministic order.
+ */
+private function sortRecursive(array &$array): void
+{
+    ksort($array);
+    foreach ($array as &$value) {
+        if (\is_array($value)) {
+            $this->sortRecursive($value);
+        }
+    }
+}

and then

-        $params = $this->getParams();
-        ksort($params);
+        $params = $this->getParams();
+        $this->sortRecursive($params);
  1. md5() is fast but no longer recommended for new code where uniqueness really matters.
    Switching to hash('sha256', …) is a one-liner and keeps collision probability astronomically low.
-        return md5($this->getURI() . '*' . serialize($params) . '*' . APP_CACHE_BUSTER);
+        return hash('sha256', $this->getURI() . '*' . serialize($params) . '*' . APP_CACHE_BUSTER);

Both tweaks are fully backwards-compatible and only strengthen the consistency guarantees of the new helper.

app/controllers/shared/api.php (1)

827-851: Minor nit – consider re-using the already computed $key

$key is now generated once earlier (line 561). Generating it again here is cheap but redundant; re-using the existing variable eliminates an extra call to getParams() and SHA/MD5 work:

-                $key = $request->cacheIdentifier();
+                // `$key` was computed earlier when checking the cache
+                // and is still in scope.

Not critical, but an easy micro-optimisation.

src/Appwrite/Platform/Workers/Deletes.php (1)

528-540: Named argument supplied out of order – may trip static analysers

The mixed positional/named invocation

$this->deleteByGroup(
    $collection->getId(),
    [...],
    database: $dbForProject
);

is perfectly valid in PHP 8, but some static analysers (Psalm, PHPStan < 1.10) still flag it because only the third parameter is named. To silence false positives and improve readability, either:

  1. Name all arguments, or
  2. Drop the name altogether.

Example:

$this->deleteByGroup(
    collection: $collection->getId(),
    queries:   [Query::select($this->selects), Query::orderAsc()],
    database:  $dbForProject
);

This is a nit, but it helps tooling and future maintenance.

app/controllers/api/databases.php (2)

885-897: Unused $mode parameter can be removed

$mode is injected and accepted as an argument but never referenced in the action body. Keeping it around clutters the signature.

-    ->inject('mode')
...
-    ->action(function (..., bool $enabled, Response $response, Database $dbForProject, string $mode, Event $queueForEvents) {
+    ->action(function (..., bool $enabled, Response $response, Database $dbForProject, Event $queueForEvents) {

The same injection appears in the updateCollection route below – please purge both occurrences.


1207-1220: Duplicate unused $mode argument in update-collection route

$mode is injected but never used here either. Removing it will simplify the handler and avoid future confusion.

app/init/resources.php (1)

512-514: Inconsistent removal of telemetry & missing root path for Local device

deviceForLocal now returns new Local() without the Device\Telemetry wrapper and without an explicit root path.
All other deviceFor* resources still wrap their devices with telemetry, so this change introduces an inconsistency and may break instrumentation expectations later on.
Moreover, Utopia\Storage\Device\Local usually expects a root directory; instantiating it with no argument falls back to the current working dir, which is unlikely to be the intended uploads location.

Suggested follow-up:

-return new Local();
+// Decide whether telemetry should be dropped everywhere or re-add it here.
+// If keeping telemetry _off_, provide an explicit root folder:
+return new Local(APP_STORAGE_UPLOADS);

Please verify the design decision and adjust the remaining deviceFor* resources (or revert this one) for consistent behaviour.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between d3ba4da and d577fd1.

📒 Files selected for processing (9)
  • app/config/storage/inputs.php (0 hunks)
  • app/config/storage/outputs.php (0 hunks)
  • app/controllers/api/databases.php (68 hunks)
  • app/controllers/general.php (1 hunks)
  • app/controllers/shared/api.php (2 hunks)
  • app/init/resources.php (1 hunks)
  • app/worker.php (1 hunks)
  • src/Appwrite/Platform/Workers/Deletes.php (1 hunks)
  • src/Appwrite/Utopia/Request.php (1 hunks)
💤 Files with no reviewable changes (2)
  • app/config/storage/outputs.php
  • app/config/storage/inputs.php
🧰 Additional context used
🧬 Code Graph Analysis (2)
app/controllers/shared/api.php (1)
src/Appwrite/Utopia/Request.php (1)
  • cacheIdentifier (230-235)
src/Appwrite/Platform/Workers/Deletes.php (1)
src/Appwrite/Platform/Workers/Databases.php (1)
  • deleteByGroup (568-587)
🪛 GitHub Actions: Linter
app/worker.php

[error] 1-1: Parse error: syntax error, unexpected identifier "getDevic…" causing PSR 12 lint failure.

⏰ 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 (2)
app/controllers/shared/api.php (1)

561-568: Good move – single source of truth for cache keys

Replacing the ad-hoc hash with $request->cacheIdentifier() removes duplication and makes future changes to the hashing scheme painless.
No behavioural change is expected as the helper still returns an MD5 of the original components.

app/controllers/general.php (1)

1166-1168: Verify coverage of other database exceptions after cleanup

Only Authorization and Timeout are now mapped to AppwriteExceptions.
Previously, cases such as Conflict, NotFound, Duplicate, etc., were translated as well (per the earlier code base).
If those exceptions can still bubble up from lower layers, they will now fall through to the generic branch and surface as 500 “Server Error”, degrading DX.

Please double-check whether:

  • upstream layers have been updated to catch/translate those exceptions, or
  • they are no longer thrown.

If not, consider restoring / adding dedicated mappings similar to:

case 'Utopia\Database\Exception\Conflict':
    $error = new AppwriteException(AppwriteException::DATABASE_CONFLICT, previous: $error);
    break;

src/Appwrite/Platform/Workers/Deletes.php Show resolved Hide resolved
src/Appwrite/Platform/Workers/Deletes.php Show resolved Hide resolved
app/worker.php Outdated Show resolved Hide resolved
app/worker.php Outdated Show resolved Hide resolved
Copy link

github-actions bot commented May 17, 2025

✨ Benchmark results

  • Requests per second: 1,005
  • Requests with 200 status code: 180,939
  • P99 latency: 0.182946185

⚡ Benchmark Comparison

Metric This PR Latest version
RPS 1,005 1,316
200 180,939 236,891
P99 0.182946185 0.139610523

@abnegate abnegate merged commit 1888606 into 1.7.x May 17, 2025
149 of 150 checks passed
@abnegate abnegate deleted the feat-sync-1.6.x branch May 17, 2025 11:43
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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.