Skip to content

Conversation

@SaurFort
Copy link
Contributor

@SaurFort SaurFort commented Aug 20, 2025

When using the decimal prefix and setting 16 GB of RAM, the panel displayed 16.79 GB (without overhead) instead of 16 GB (without overhead).
This was due to the using of a binary multiplier (2^20), which is only correct for MiB/GiB.

So I've used the config('panel.use_binary_prefix') to check what multiplier should be used.

This is a visual fix, but I think it's better like that.

@coderabbitai
Copy link

coderabbitai bot commented Aug 20, 2025

📝 Walkthrough

Walkthrough

Updated memoryUsage() in ServerOverview.php to compute totalMemory using 1024*1024 when config('panel.use_binary_prefix') is true, otherwise 1_000_000; fetching latest memory, formatting, and return structure remain unchanged.

Changes

Cohort / File(s) Summary of Changes
Server widget memory unit handling
app/Filament/Server/Widgets/ServerOverview.php
totalMemory calculation now uses 1024*1024 when config('panel.use_binary_prefix') is true, otherwise 1_000_000. Remaining memoryUsage() logic (fetch latest memory, convert_bytes_to_readable, return) unchanged.

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


🪧 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 20, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
app/Filament/Server/Widgets/ServerOverview.php (1)

98-104: Escape clipboard value to prevent JS injection in $this->js()

Interpolating raw $value inside a quoted JS string can break the script or enable XSS if the value contains quotes or JS-significant characters (e.g., a malicious server name). Use json_encode to safely embed the value.

Apply this diff:

-        $this->js("window.navigator.clipboard.writeText('{$value}');");
+        $this->js('window.navigator.clipboard.writeText(' . json_encode($value) . ');');

Optional: you can also leverage Filament/Livewire’s built-in copy-to-clipboard patterns to avoid manual JS string interpolation altogether.

🧹 Nitpick comments (2)
app/Filament/Server/Widgets/ServerOverview.php (2)

71-71: Correct fix for decimal vs binary units; consider extracting a shared multiplier helper

This resolves the 16 vs 16.79 GB mismatch when decimal prefixes are selected. To avoid duplication and keep disk/memory consistent, extract a single helper that returns bytes per MB based on the config and use it in both memory and disk.

Apply this diff to use a helper on this line:

-        $totalMemory = $this->server->memory * (config('panel.use_binary_prefix') ? 2 ** 20 : 1000 * 1000);
+        $totalMemory = $this->server->memory * $this->bytesPerMegabyte();

Add this helper method to the class (outside the shown range):

private function bytesPerMegabyte(): int
{
    // Default to binary to preserve previous behavior if the config key is missing.
    return config('panel.use_binary_prefix', true) ? 1024 * 1024 : 1000 * 1000;
}

Would you like me to open a follow-up PR that introduces this helper and uses it across the widget?


87-87: Keep unit conversion consistent between memory and disk

To make unit handling uniform (and reduce chances of drift), use the same helper for disk as proposed for memory.

Apply this diff:

-        $totalBytes = $this->server->disk * (config('panel.use_binary_prefix') ? 1024 * 1024 : 1000 * 1000);
+        $totalBytes = $this->server->disk * $this->bytesPerMegabyte();
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 42db5b3 and 41d21cd.

📒 Files selected for processing (1)
  • app/Filament/Server/Widgets/ServerOverview.php (1 hunks)
🔇 Additional comments (1)
app/Filament/Server/Widgets/ServerOverview.php (1)

71-71: No action needed: use_binary_prefix has a default
The use_binary_prefix key is defined in config/panel.php with env('PANEL_USE_BINARY_PREFIX', true), ensuring config('panel.use_binary_prefix') always returns a boolean.

@SaurFort
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@SaurFort
Copy link
Contributor Author

recheck

From 2 ** 20 to 1024 * 1024

Co-authored-by: Boy132 <Boy132@users.noreply.github.com>
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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
app/Filament/Server/Widgets/ServerOverview.php (1)

98-98: Escape JS payload when injecting $value into copyClick to prevent breakage/XSS

Interpolating $value directly into a JS string can break on quotes and is vulnerable to script injection. Use JSON-safe embedding.

Apply this diff:

-        $this->js("window.navigator.clipboard.writeText('{$value}');");
+        $this->js('window.navigator.clipboard.writeText(' . \Illuminate\Support\Js::from($value) . ');');

And add the import near the other use statements (outside the selected range):

use Illuminate\Support\Js;
🧹 Nitpick comments (1)
app/Filament/Server/Widgets/ServerOverview.php (1)

71-71: DRY the MB→bytes multiplier into a helper to keep memory/disk consistent

Centralize the multiplier logic so future changes (e.g., adding KiB/KB granularity) happen in one place and both memory/disk remain in sync.

Apply this diff to use a helper at both call sites:

-        $totalMemory = $this->server->memory * (config('panel.use_binary_prefix') ? 1024 * 1024 : 1000 * 1000);
+        $totalMemory = $this->server->memory * $this->bytesPerMB();
-        $totalBytes = $this->server->disk * (config('panel.use_binary_prefix') ? 1024 * 1024 : 1000 * 1000);
+        $totalBytes = $this->server->disk * $this->bytesPerMB();

Add this helper method to the class (outside the selected ranges):

private function bytesPerMB(): int
{
    return config('panel.use_binary_prefix') ? 1024 * 1024 : 1000 * 1000;
}

Also applies to: 87-87

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 41d21cd and ec82b8b.

📒 Files selected for processing (1)
  • app/Filament/Server/Widgets/ServerOverview.php (1 hunks)
🔇 Additional comments (1)
app/Filament/Server/Widgets/ServerOverview.php (1)

71-71: Correct multiplier selection for decimal vs binary prefixes — fix looks good

This aligns memory total with the configured prefix policy and matches the existing disk logic. It addresses the reported 16 GB vs 16.79 GB display issue.

@SaurFort SaurFort requested a review from Boy132 August 20, 2025 19:23
@Boy132 Boy132 merged commit 76451fa into pelican-dev:main Aug 31, 2025
25 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Aug 31, 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.

3 participants