Ori.livneh has uploaded a new change for review.
https://gerrit.wikimedia.org/r/92895
Change subject: mw.inspect: add report for mw.loader.store
......................................................................
mw.inspect: add report for mw.loader.store
Adds a 'store' report to mw.inspect, which outputs:
* Whether localStorage module caching is enabled.
* Cache hit / miss counts.
* Number of items purged from the cache.
* Total size of the cache blob in localStorage.
Rather than duplicate the logic that converted a numeric byte count to a
human-readable format, I moved it to new helper function: humanSize.
Change-Id: I5b98322ba843f32e6a99829b4cf3d8fb0bc61514
---
M resources/mediawiki/mediawiki.inspect.js
1 file changed, 24 insertions(+), 4 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/95/92895/1
diff --git a/resources/mediawiki/mediawiki.inspect.js
b/resources/mediawiki/mediawiki.inspect.js
index 454d1a4..8df4e88 100644
--- a/resources/mediawiki/mediawiki.inspect.js
+++ b/resources/mediawiki/mediawiki.inspect.js
@@ -14,6 +14,13 @@
} );
}
+ function humanSize( bytes ) {
+ if ( !$.isNumeric( bytes ) ) { return null; }
+ var i = 0, units = [ '', ' kB', ' MB', ' GB', ' TB', ' PB' ];
+ for ( ; bytes >= 1024; bytes /= 1024 ) { i++; }
+ return Math.max( bytes, 0.1 ).toFixed( 1 ) + units[i];
+ }
+
/**
* @class mw.inspect
* @singleton
@@ -181,9 +188,7 @@
// Convert size to human-readable string.
$.each( modules, function ( i, module ) {
- module.size = module.size > 1024 ?
- ( module.size / 1024 ).toFixed(
2 ) + ' KB' :
- ( module.size !== null ?
module.size + ' B' : null );
+ module.size = humanSize( module.size );
} );
return modules;
@@ -214,7 +219,22 @@
} );
sortByProperty( modules, 'allSelectors', true );
return modules;
- }
+ },
+
+ /**
+ * Report stats on mw.loader.store: the number of
localStorage
+ * cache hits and misses, the number of items purged
from the
+ * cache, and the total size of the module blob in
localStorage.
+ */
+ store: function () {
+ var raw, stats = { enabled:
mw.loader.store.enabled };
+ if ( stats.enabled ) {
+ $.extend( stats, mw.loader.store.stats
);
+ raw = localStorage.getItem(
mw.loader.store.getStoreKey() );
+ stats.totalSize = humanSize(
$.byteLength( raw ) );
+ }
+ return stats;
+ },
}
};
--
To view, visit https://gerrit.wikimedia.org/r/92895
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5b98322ba843f32e6a99829b4cf3d8fb0bc61514
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits