Conversation
Security Scan Results for PRDocker Image Scan Results
Source Code Scan Results🎉 No vulnerabilities found! |
✨ Benchmark results
⚡ Benchmark Comparison
|
📝 WalkthroughWalkthroughReplaces module-level static/global caches in app/realtime.php with per-coroutine context caching via Swoole\Coroutine::getContext(). The functions getConsoleDB, getProjectDB, getCache, getRedis, getTimelimit, getRealtime, and getTelemetry now read and write cached values on the coroutine context (keys include Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
app/realtime.php (1)
82-99: Consider reordering the empty/console check before the cache lookup.The cache lookup at line 88 calls
$project->getSequence()before checking if the project is empty or console at line 97. Moving the short-circuit check earlier would avoid unnecessary cache operations for console/empty projects.$ctx = Coroutine::getContext(); - if (!isset($ctx['getProjectDB'])) { - $ctx['getProjectDB'] = []; - } - - if (isset($ctx['getProjectDB'][$project->getSequence()])) { - return $ctx['getProjectDB'][$project->getSequence()]; - } - - global $register; - - /** @var Group $pools */ - $pools = $register->get('pools'); - if ($project->isEmpty() || $project->getId() === 'console') { return getConsoleDB(); } + + if (!isset($ctx['getProjectDB'])) { + $ctx['getProjectDB'] = []; + } + + if (isset($ctx['getProjectDB'][$project->getSequence()])) { + return $ctx['getProjectDB'][$project->getSequence()]; + } + + global $register; + + /** @var Group $pools */ + $pools = $register->get('pools');
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
app/realtime.php(6 hunks)
⏰ 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: Benchmark
- GitHub Check: Setup & Build Appwrite Image
- GitHub Check: scan
🔇 Additional comments (3)
app/realtime.php (3)
53-76: LGTM!The coroutine context caching pattern is correctly implemented: context retrieval, cache check, lazy initialization, and storage in context before return.
136-158: LGTM!The coroutine context caching is correctly implemented with proper cache key usage.
161-183: LGTM!The coroutine context caching is correctly implemented. The Redis connection object is appropriately cached per-coroutine.
There was a problem hiding this comment.
Actionable comments posted: 0
♻️ Duplicate comments (1)
app/realtime.php (1)
185-195: Key coroutine cache forgetTimelimitby(key, limit, seconds)to avoid cross‑contamination.
getTimelimit()now accepts and uses$key,$limit, and$secondswhen constructingTimeLimitRedis, which fixes the earlier “parameters ignored” bug. However, the coroutine cache always uses a single'timelimit'entry, so the first call in a coroutine determines the configuration for all subsequent calls, even if different arguments are passed (e.g. if another caller or resource uses a different key/limit/window in the same coroutine).To keep instances correctly scoped to their configuration while still caching per coroutine, cache by a composite context key derived from the arguments:
function getTimelimit(string $key = "", int $limit = 0, int $seconds = 1): TimeLimitRedis { $ctx = Coroutine::getContext(); - if (isset($ctx['timelimit'])) { - return $ctx['timelimit']; - } - - return $ctx['timelimit'] = new TimeLimitRedis($key, $limit, $seconds, getRedis()); + $cacheKey = "timelimit:{$key}:{$limit}:{$seconds}"; + + if (isset($ctx[$cacheKey])) { + return $ctx[$cacheKey]; + } + + return $ctx[$cacheKey] = new TimeLimitRedis($key, $limit, $seconds, getRedis()); }This preserves the new signature and avoids different abuse‑limit configurations unintentionally sharing a single
TimeLimitRedisinstance within a coroutine.
🧹 Nitpick comments (1)
app/realtime.php (1)
198-208: Clarify unused$workerIdingetTelemetry(and minor note ongetRealtime).
getRealtime()’s coroutine‑context cache via$ctx['realtime']is fine, and the global$realtime = getRealtime();keeps the single instance used throughout this file.In
getTelemetry(int $workerId), the$workerIdparameter is currently unused, which is what PHPMD flags. If that’s intentional (e.g. placeholder for a future adapter that differentiates by worker), it would help static analysis and reader clarity to either:
- Rename it to
$_workerIdto explicitly mark it unused, or- Add a short docblock comment noting that it’s unused by the current
NoTelemetryimplementation but kept for API compatibility.Example:
-function getTelemetry(int $workerId): Utopia\Telemetry\Adapter +function getTelemetry(int $_workerId): Utopia\Telemetry\Adapter { $ctx = Coroutine::getContext();Also applies to: 211-222
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
app/realtime.php(6 hunks)
🧰 Additional context used
🪛 PHPMD (2.15.0)
app/realtime.php
212-212: Avoid unused parameters such as '$workerId'. (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). (3)
- GitHub Check: Setup & Build Appwrite Image
- GitHub Check: Setup & Build Appwrite Image
- GitHub Check: scan
🔇 Additional comments (3)
app/realtime.php (3)
54-75: Per‑coroutine console DB caching looks correct.Using
Coroutine::getContext()with a singledbForPlatformentry per coroutine and deferring theglobal $registerlookup until after the cache check is a clean refactor from the old static cache. No behavioral issues spotted here.
80-132: Project DB coroutine context cache is consistent and preserves existing behavior.Initializing
$ctx['dbForProject']as a per‑coroutine map keyed bygetSequence()and short‑circuiting console/empty projects togetConsoleDB()keeps the previous semantics while making instances coroutine‑local. This looks good and avoids extra DSN parsing for the console project.
137-157: Cache and Redis factories match the new coroutine‑context pattern.Both
getCache()andgetRedis()now correctly reuse instances within a coroutine via$ctx['cache']/$ctx['redis'], while avoiding$register/env work on the hot path when already cached. The refactor is consistent with the DB helpers and doesn’t introduce new behavioral changes.Also applies to: 161-182
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