Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

index size in human readable format. #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions app/classes/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,38 @@ protected function _highlight($var, $format = "array", $label = false) {
return $string;
}

/**
* Export IndexSizes as string.
*
* @param mixed $var variable to be exported
* @return string
*/
protected function _highlightIndexSizes($var) {
$string = "<table cellspacing='0' cellpadding='0' style='width:100%;border:0px solid #cccccc'>";
$c = 0;
foreach($var as $key => $value) {
if ($value < 1024) {
$formatted_size = $value . "b";
} else if ($value < 1024 * 1024) {
$formatted_size = round($value/1024, 2) . " kb";
} else if ($value < 1024 * 1024 * 1024) {
$formatted_size = round($value/1024/1024, 2) . " mb";
} else if ($value < 1024 * 1024 * 1024 * 1024) {
$formatted_size = round($value/1024/1024/1024, 2) . " gb";
}
if (($c%2) == 0) {
$bgc = "#fff";
} else {
$bgc = "#eee";
}
$string .= "<tr style='background-color: " . $bgc . "'><td style='border:1px solid #cccccc'>" . $key . "</td>";
$string .= "<td style='border:1px solid #cccccc' title='(" . $value . " bytes)'>" . $formatted_size . "</td></tr>";
$c++;
}
$string .= "</table>";
return $string;
}

/**
* format bytes to human size
*
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,11 @@ public function doCollectionStats() {
$this->stats = $ret;
foreach ($this->stats as $index => $stat) {
if (is_array($stat)) {
$this->stats[$index] = $this->_highlight($stat, "json");
if ($index == "indexSizes") {
$this->stats[$index] = $this->_highlightIndexSizes($stat, "json");
} else {
$this->stats[$index] = $this->_highlight($stat);
}
}
}
}
Expand Down