Skip to content

fix: parse dmidecode memory capacity labels consistently across versions#2562

Open
ljm42 wants to merge 1 commit intomasterfrom
fix-dmidecode-parsing
Open

fix: parse dmidecode memory capacity labels consistently across versions#2562
ljm42 wants to merge 1 commit intomasterfrom
fix-dmidecode-parsing

Conversation

@ljm42
Copy link
Member

@ljm42 ljm42 commented Feb 27, 2026

dmidecode always uses binary math but 3.6 and lower report MB/GB/TB, 3.7 correctly reports MiB/GiB/TiB.

Summary by CodeRabbit

  • Bug Fixes
    • Standardized memory unit display across system information pages, ensuring consistent formatting of memory sizes using normalized binary units (KiB, MiB, GiB, TiB) for improved clarity.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 27, 2026

Walkthrough

The changes normalize memory unit handling across two plugin files by introducing consistent memory units mapping and parsing functions to convert memory size strings to MiB, replacing ad-hoc parsing logic previously used in memory display calculations.

Changes

Cohort / File(s) Summary
Memory Unit Normalization
emhttp/plugins/dynamix/DashStats.page, emhttp/plugins/dynamix/scripts/system_information
Introduced memory_units mapping for base-1024 unit conversions (kb/kib through pb/pib). Added parse_memory_to_mib() and normalize_binary_unit() functions to standardize memory size parsing and formatting. Replaced previous ad-hoc memory parsing logic with new functions across memory device aggregation, installed memory calculations, and display output generation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Memory units, now unified with grace,

Base-1024 conversions in their place,

Parsing functions dance, all neat and tight,

Where kibibytes and megabytes align just right! ✨

No more ad-hoc madness, the code's delight.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: implementing consistent parsing of dmidecode memory capacity labels across different versions by normalizing SI and IEC units to base-1024 equivalents.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-dmidecode-parsing

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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.

@github-actions
Copy link

🔧 PR Test Plugin Available

A test plugin has been generated for this PR that includes the modified files.

Version: 2026.02.27.1909
Build: View Workflow Run

📥 Installation Instructions:

Install via Unraid Web UI:

  1. Go to Plugins → Install Plugin
  2. Copy and paste this URL:
https://preview.dl.unraid.net/pr-plugins/pr-2562/webgui-pr-2562.plg
  1. Click Install

Alternative: Direct Download

⚠️ Important Notes:

  • Testing only: This plugin is for testing PR changes
  • Backup included: Original files are automatically backed up
  • Easy removal: Files are restored when plugin is removed
  • Conflicts: Remove this plugin before installing production updates

📝 Modified Files:

Click to expand file list
emhttp/plugins/dynamix/DashStats.page
emhttp/plugins/dynamix/scripts/system_information

🔄 To Remove:

Navigate to Plugins → Installed Plugins and remove webgui-pr-2562, or run:

plugin remove webgui-pr-2562

🤖 This comment is automatically generated and will be updated with each new push to this PR.

Copy link
Contributor

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

🧹 Nitpick comments (2)
emhttp/plugins/dynamix/DashStats.page (2)

193-204: Inconsistent formatting compared to system_information.

The nested } else { if structure with braces on the same line as content is harder to read than the equivalent elseif chain used in system_information (lines 139-149). Consider aligning the formatting for consistency:

♻️ Suggested formatting improvement
 if ($memory_installed >= 1048576) {
   $memory_installed = round($memory_installed/1048576);
   $memory_maximum = round($memory_maximum/1048576);
   $memory_unit = 'TiB';
-} else { 
-if ($memory_installed >= 1024) {
+} elseif ($memory_installed >= 1024) {
   $memory_installed = round($memory_installed/1024);
   $memory_maximum = round($memory_maximum/1024);
-  $memory_unit = 'GiB';}
-else $memory_unit = 'MiB'; }
+  $memory_unit = 'GiB';
+} else {
+  $memory_unit = 'MiB';
+}
 
 $unit = $memory_unit;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@emhttp/plugins/dynamix/DashStats.page` around lines 193 - 204, The memory
unit selection block uses a nested "} else { if" style that is inconsistent with
the `system_information` formatting; change the logic around `memory_installed`,
`memory_maximum`, and `memory_unit` to a clear elseif chain (e.g., if (...) {
... } elseif (...) { ... } else { ... }) and place braces consistently on their
own lines to match the `system_information` style, then assign `unit =
$memory_unit` as before.

166-180: Consider extracting shared memory parsing logic to avoid duplication.

The $memory_units array and $parse_memory_to_mib function are duplicated verbatim from scripts/system_information. This creates a maintenance burden if the logic needs to be updated in the future.

Consider extracting these into a shared helper file (e.g., in include/Helpers.php) that both files can require_once.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@emhttp/plugins/dynamix/DashStats.page` around lines 166 - 180, The
$memory_units array and the $parse_memory_to_mib closure are duplicated; extract
them into a shared helper (e.g., a common PHP helper that returns the units
array and a parseMemoryToMiB function) and replace the local definitions in
DashStats.page with a require_once of that helper and calls to the shared
function(s) (look for symbols $memory_units and $parse_memory_to_mib to locate
the code to remove). Ensure the shared helper exposes a callable
parseMemoryToMiB($value) that replicates the current behavior (regex,
strtolower, rounding and int cast) and update any other files that currently
duplicate the logic to use the same helper.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@emhttp/plugins/dynamix/DashStats.page`:
- Around line 193-204: The memory unit selection block uses a nested "} else {
if" style that is inconsistent with the `system_information` formatting; change
the logic around `memory_installed`, `memory_maximum`, and `memory_unit` to a
clear elseif chain (e.g., if (...) { ... } elseif (...) { ... } else { ... })
and place braces consistently on their own lines to match the
`system_information` style, then assign `unit = $memory_unit` as before.
- Around line 166-180: The $memory_units array and the $parse_memory_to_mib
closure are duplicated; extract them into a shared helper (e.g., a common PHP
helper that returns the units array and a parseMemoryToMiB function) and replace
the local definitions in DashStats.page with a require_once of that helper and
calls to the shared function(s) (look for symbols $memory_units and
$parse_memory_to_mib to locate the code to remove). Ensure the shared helper
exposes a callable parseMemoryToMiB($value) that replicates the current behavior
(regex, strtolower, rounding and int cast) and update any other files that
currently duplicate the logic to use the same helper.

ℹ️ Review info

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between c435862 and fc82ca2.

📒 Files selected for processing (2)
  • emhttp/plugins/dynamix/DashStats.page
  • emhttp/plugins/dynamix/scripts/system_information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants