Browse Source

remove old utils.formatBytes and replace with new, flexible utils.formatLargeNumber

fix-133-memory-crash
Dan Janosik 7 years ago
parent
commit
fd9cc6d232
  1. 15
      app/utils.js
  2. 9
      views/mempool-summary.pug
  3. 16
      views/node-status.pug

15
app/utils.js

@ -81,20 +81,6 @@ function getRandomString(length, chars) {
return result;
}
function formatBytes(bytesInt) {
var scales = [ {val:1000000000000000, name:"PB"}, {val:1000000000000, name:"TB"}, {val:1000000000, name:"GB"}, {val:1000000, name:"MB"}, {val:1000, name:"KB"} ];
for (var i = 0; i < scales.length; i++) {
var item = scales[i];
var fraction = Math.floor(bytesInt / item.val);
if (fraction >= 1) {
return fraction.toLocaleString() + " " + item.name;
}
}
return Math.floor(bytesInt) + " B";
}
var formatCurrencyCache = {};
function formatCurrencyAmount(amount, formatType) {
@ -345,7 +331,6 @@ module.exports = {
hex2ascii: hex2ascii,
splitArrayIntoChunks: splitArrayIntoChunks,
getRandomString: getRandomString,
formatBytes: formatBytes,
formatCurrencyAmount: formatCurrencyAmount,
formatExchangedCurrency: formatExchangedCurrency,
addThousandsSeparators: addThousandsSeparators,

9
views/mempool-summary.pug

@ -16,11 +16,16 @@ block content
tr
th(class="table-active properties-header") Transaction Count
td #{getmempoolinfo.size.toLocaleString()}
tr
- var mem1Data = utils.formatLargeNumber(getmempoolinfo.usage, 2);
- var mem2Data = utils.formatLargeNumber(getmempoolinfo.bytes, 2);
th(class="table-active properties-header") Memory Usage
td(class="monospace")
span #{utils.formatBytes(getmempoolinfo.usage)}
span(class="text-muted") (virtual size: #{utils.formatBytes(getmempoolinfo.bytes)})
span #{mem1Data[0]} #{mem1Data[1].abbreviation}B
span(class="text-muted") (virtual size: #{mem2Data[0]} #{mem2Data[1].abbreviation}B)
tr
th(class="table-active properties-header") Total Fees
td(class="monospace")

16
views/node-status.pug

@ -37,9 +37,10 @@ block content
td(class="monospace") #{getnetworkinfo.protocolversion}
if (getblockchaininfo.size_on_disk)
- var sizeData = utils.formatLargeNumber(getblockchaininfo.size_on_disk, 2);
tr
th(class="table-active properties-header") Blockchain Size
td(class="monospace") #{utils.formatBytes(getblockchaininfo.size_on_disk)}
td(class="monospace") #{sizeData[0]} #{sizeData[1].abbreviation}B
br
span(class="text-muted") (pruned: #{getblockchaininfo.pruned})
tr
@ -78,11 +79,16 @@ block content
tr
th(class="table-active properties-header") Network Traffic
td(class="monospace")
span Total Download: #{utils.formatBytes(getnettotals.totalbytesrecv)}
span(class="text-muted") (avg #{utils.formatBytes(getnettotals.totalbytesrecv / uptimeSeconds)}/s)
- var downData = utils.formatLargeNumber(getnettotals.totalbytesrecv, 2);
- var downRateData = utils.formatLargeNumber(getnettotals.totalbytesrecv / uptimeSeconds, 2);
- var upData = utils.formatLargeNumber(getnettotals.totalbytessent, 2);
- var upRateData = utils.formatLargeNumber(getnettotals.totalbytessent / uptimeSeconds, 2);
span Total Download: #{downData[0]} #{downData[1].abbreviation}B
span(class="text-muted") (avg #{downRateData[0]} #{downRateData[1].abbreviation}B/s)
br
span Total Upload: #{utils.formatBytes(getnettotals.totalbytessent)}
span(class="text-muted") (avg #{utils.formatBytes(getnettotals.totalbytessent / uptimeSeconds)}/s)
span Total Upload: #{upData[0]} #{upData[1].abbreviation}B
span(class="text-muted") (avg #{upRateData[0]} #{upRateData[1].abbreviation}B/s)
tr(class="border-bottom")
th(class="table-active properties-header") Warnings

Loading…
Cancel
Save