PadMessageHandler: Improve readability

This commit is contained in:
Richard Hansen 2021-03-21 14:52:39 -04:00
parent 019e296c4a
commit d8cbd134d3

View file

@ -1256,39 +1256,22 @@ const getChangesetInfo = async (padId, startNum, endNum, granularity) => {
revTimesNeeded.push(end - 1); revTimesNeeded.push(end - 1);
} }
// get all needed db values parallel - no await here since // Get all needed db values in parallel.
// it would make all the lookups run in series
// get all needed composite Changesets
const composedChangesets = {}; const composedChangesets = {};
const p1 = Promise.all(
compositesChangesetNeeded.map(
(item) => composePadChangesets(
padId, item.start, item.end
).then(
(changeset) => {
composedChangesets[`${item.start}/${item.end}`] = changeset;
}
)
)
);
// get all needed revision Dates
const revisionDate = []; const revisionDate = [];
const p2 = Promise.all(revTimesNeeded.map((revNum) => pad.getRevisionDate(revNum) const [lines] = await Promise.all([
.then((revDate) => { getPadLines(padId, startNum - 1),
revisionDate[revNum] = Math.floor(revDate / 1000); // Get all needed composite Changesets.
}) ...compositesChangesetNeeded.map(async (item) => {
)); const changeset = await composePadChangesets(padId, item.start, item.end);
composedChangesets[`${item.start}/${item.end}`] = changeset;
// get the lines }),
let lines; // Get all needed revision Dates.
const p3 = getPadLines(padId, startNum - 1).then((_lines) => { ...revTimesNeeded.map(async (revNum) => {
lines = _lines; const revDate = await pad.getRevisionDate(revNum);
}); revisionDate[revNum] = Math.floor(revDate / 1000);
}),
// wait for all of the above to complete ]);
await Promise.all([p1, p2, p3]);
// doesn't know what happens here exactly :/ // doesn't know what happens here exactly :/
const timeDeltas = []; const timeDeltas = [];