Skip to content

Conversation

@Boy132
Copy link
Member

@Boy132 Boy132 commented Oct 13, 2025

Closes #1793

@Boy132 Boy132 self-assigned this Oct 13, 2025
@coderabbitai
Copy link

coderabbitai bot commented Oct 13, 2025

📝 Walkthrough

Walkthrough

Updated 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

Cohort / File(s) Summary of Changes
Server stats caching
app/Filament/Server/Widgets/ServerConsole.php
storeStats now uses a local $cachedStats variable, appends the new sample, trims the array with array_slice(..., -120) to keep only the last 120 entries, and writes the trimmed array back to cache; cache key and TTL unchanged; no exported/public declarations changed.

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
Loading

Pre-merge checks

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly and concisely summarizes the primary change of the pull request by stating that only the last 120 stored stats are retained, matching the actual code modification in ServerConsole::storeStats.
Linked Issues Check ✅ Passed The changes in ServerConsole::storeStats implement trimming of Redis cache entries to the last 120 stats, directly fulfilling the linked issue’s requirement to remove old graph data and prevent unbounded growth.
Out of Scope Changes Check ✅ Passed All modifications are confined to trimming stored stats in the caching logic of ServerConsole::storeStats, with no unrelated files or features altered.
Description Check ✅ Passed The pull request description indicates that it closes issue #1793, directly relating the changes to the linked issue’s requirements of trimming stored stats, so it is clearly on topic.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 58d90b9 and 2e792d4.

📒 Files selected for processing (1)
  • app/Filament/Server/Widgets/ServerConsole.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/Filament/Server/Widgets/ServerConsole.php

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.

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: 0

🧹 Nitpick comments (1)
app/Filament/Server/Widgets/ServerConsole.php (1)

118-128: Consider renaming variable for clarity.

The variable name $data is reused for two different purposes: the decoded JSON (line 118) and the cached array (line 124). While not incorrect, using distinct names like $stats and $cachedData would 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

📥 Commits

Reviewing files that changed from the base of the PR and between d735e85 and 58d90b9.

📒 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.

@Boy132 Boy132 merged commit 2cd9fa2 into main Oct 13, 2025
25 checks passed
@Boy132 Boy132 deleted the boy132/slice-stats branch October 13, 2025 20:50
@github-actions github-actions bot locked and limited conversation to collaborators Oct 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Internal network usage increases the longer you have the console of a server open

4 participants