Skip to content

Commit

Permalink
Use sumSizesOf in comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sgomes committed Dec 16, 2020
1 parent 326392d commit aa45754
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 4 additions & 5 deletions server/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { log, getPRNumber } = require('./utils');
const db = require('./db');
const gh = require('./github');
const printDeltaTable = require('./delta-table');
const { sumSizesOf, ZERO_SIZE } = require('./delta');

const REPO = 'Automattic/wp-calypso';
const WATERMARK = 'c52822';
Expand Down Expand Up @@ -37,7 +38,7 @@ function groupByArea(deltas) {

function totalDeltasForArea(areaDelta, delta) {
if (!areaDelta) {
return {};
return {...ZERO_SIZE};
}

// Produce an array of arrays:
Expand All @@ -62,12 +63,10 @@ function totalDeltasForArea(areaDelta, delta) {
.map((property, index) => chunksInUse[index].reduce(
(acc, chunkName) => {
const chunk = delta.chunks.find(chunk => chunk.name === chunkName) || {};
for (const sizeType in chunk[property]) {
acc[sizeType] = chunk[property][sizeType] + (acc[sizeType] || 0);
}
acc = sumSizesOf(acc, chunk[property]);
return acc;
},
{}
{...ZERO_SIZE}
));

// Produce a single object with the delta between first and second commit:
Expand Down
3 changes: 3 additions & 0 deletions server/delta.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const _ = require('lodash');

const sizes = ['stat_size', 'parsed_size', 'gzip_size'];
const ZERO_SIZE = sizes.reduce((acc, size) => ({...acc, [size]: 0}), {});

function sizesOf(stat) {
return stat ? _.pick(stat, sizes) : null;
Expand Down Expand Up @@ -266,3 +267,5 @@ function deltaFromStatsAndGroups(firstStats, firstGroups, secondStats, secondGro

exports.deltaFromStats = deltaFromStats;
exports.deltaFromStatsAndGroups = deltaFromStatsAndGroups;
exports.sumSizesOf = sumSizesOf;
exports.ZERO_SIZE = ZERO_SIZE;

0 comments on commit aa45754

Please sign in to comment.