add support for an optional handler for each pin log
great for analyzing which files are most in need of optimization
This commit is contained in:
@@ -3,32 +3,43 @@ const Pins = require("../../lib/pins");
|
||||
|
||||
var stats = {
|
||||
users: 0,
|
||||
lines: 0,
|
||||
pinned: 0,
|
||||
events: 0,
|
||||
lines: 0, // how many lines did you iterate over
|
||||
surplus: 0, // how many of those lines were not needed?
|
||||
pinned: 0, // how many files are pinned?
|
||||
duplicated: 0,
|
||||
};
|
||||
|
||||
var handler = function (ref, id /* safeKey */, pinned) {
|
||||
if (ref.surplus) {
|
||||
//console.log("%s has %s trimmable lines", id, ref.surplus);
|
||||
stats.surplus += ref.surplus;
|
||||
}
|
||||
|
||||
for (var item in ref.pins) {
|
||||
if (!pinned.hasOwnProperty(item)) {
|
||||
//console.log("> %s is pinned", item);
|
||||
stats.pinned++;
|
||||
} else {
|
||||
//console.log("> %s was already pinned", item);
|
||||
stats.duplicated++;
|
||||
}
|
||||
}
|
||||
|
||||
stats.users++;
|
||||
stats.lines += ref.index;
|
||||
//console.log(ref, id);
|
||||
};
|
||||
|
||||
Pins.list(function (err, pinned) {
|
||||
/*
|
||||
for (var id in pinned) {
|
||||
console.log(id);
|
||||
stats.pinned++;
|
||||
}
|
||||
*/
|
||||
console.log(stats);
|
||||
}, {
|
||||
pinPath: require("../../lib/load-config").pinPath
|
||||
pinPath: require("../../lib/load-config").pinPath,
|
||||
handler: handler,
|
||||
});
|
||||
|
||||
/*
|
||||
function (ref, safeKey, pinned) {
|
||||
stats.users++;
|
||||
stats.lines += ref.index;
|
||||
|
||||
Object.keys(ref.pins).forEach(function (id) {
|
||||
if (!pinned[id]) {
|
||||
pinned[id] = true;
|
||||
stats.pinned++;
|
||||
}
|
||||
});
|
||||
//console.log("pin", stats.events++);
|
||||
//console.log(ref, safeKey);
|
||||
}*/
|
||||
|
||||
Reference in New Issue
Block a user