-
-
Notifications
You must be signed in to change notification settings - Fork 254
Only keep the last 120 stored stats #1805
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
Conversation
📝 WalkthroughWalkthroughUpdated ServerConsole::storeStats to append a new timestamped sample and persist only the most recent 120 samples per server cache key by trimming the array before writing back to cache. Cache key format and TTL are unchanged. No public/exported interfaces were modified. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant U as User
participant W as ServerConsole Widget
participant C as Cache (Redis)
U->>W: Trigger storeStats(newSample)
W->>C: cache.get(serverKey)
C-->>W: existingData (array)
W->>W: set $cachedStats = existingData or []
W->>W: append newSample to $cachedStats
rect rgb(230,245,255)
note right of W: Trim history to last 120 entries
W->>W: $cachedStats = array_slice($cachedStats, -120)
end
W->>C: cache.put(serverKey, $cachedStats, ttl)
C-->>W: ok
W-->>U: done
Pre-merge checks❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
app/Filament/Server/Widgets/ServerConsole.php (1)
118-128: Consider renaming variable for clarity.The variable name
$datais reused for two different purposes: the decoded JSON (line 118) and the cached array (line 124). While not incorrect, using distinct names like$statsand$cachedDatawould improve readability.public function storeStats(string $data): void { - $data = json_decode($data); + $stats = json_decode($data); $timestamp = now()->getTimestamp(); - foreach ($data as $key => $value) { + foreach ($stats as $key => $value) { $cacheKey = "servers.{$this->server->id}.$key"; - $data = cache()->get($cacheKey, []); + $cachedData = cache()->get($cacheKey, []); - $data[$timestamp] = $value; + $cachedData[$timestamp] = $value; - cache()->put($cacheKey, array_slice($data, -120), now()->addMinute()); + cache()->put($cacheKey, array_slice($cachedData, -120), now()->addMinute()); } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
app/Filament/Server/Widgets/ServerConsole.php(1 hunks)
🔇 Additional comments (1)
app/Filament/Server/Widgets/ServerConsole.php (1)
128-128: Fix correctly addresses unbounded cache growth.The
array_slice($data, -120)successfully limits each cache key to 120 historical entries, directly resolving the Redis growth issue described in #1793.Note: This implementation assumes timestamps are monotonically increasing so that insertion order matches chronological order. In normal operation with synchronized clocks, this is valid, but extreme clock skew could theoretically retain non-chronological entries. Given the 1-minute cache expiration and typical NTP-synced environments, this risk is minimal.
Closes #1793