-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Sync 1.6.x #9778
Conversation
WalkthroughThe 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
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
Poem
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (1)
💤 Files with no reviewable changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (19)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one comment
Security Scan Results for PRDocker Image Scan Results
Source Code Scan Results🎉 No vulnerabilities found! |
There was a problem hiding this 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 issueIncorrect 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 thefilter
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 suggestionParameter 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 friendlyThe overall idea to centralise the cache-key logic is 👍, but two implementation details are worth another look:
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 byserialize()
.
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);
md5()
is fast but no longer recommended for new code where uniqueness really matters.
Switching tohash('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 togetParams()
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 analysersThe 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:
- Name all arguments, or
- 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 forLocal
device
deviceForLocal
now returnsnew Local()
without theDevice\Telemetry
wrapper and without an explicit root path.
All otherdeviceFor*
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
📒 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 keysReplacing 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 cleanupOnly
Authorization
andTimeout
are now mapped toAppwriteException
s.
Previously, cases such asConflict
,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;
✨ Benchmark results
⚡ Benchmark Comparison
|
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
Checklist
Summary by CodeRabbit