MCPcopy Index your code
hub / github.com/ether/etherpad / getChangesetInfo

Function getChangesetInfo

src/node/handler/PadMessageHandler.ts:1551–1622  ·  view source on GitHub ↗
(pad: PadType, startNum: number, endNum:number, granularity: number)

Source from the content-addressed store, hash-verified

1549 * https://github.com/ether/pad/blob/master/etherpad/src/etherpad/control/pad/pad_changeset_control.js#L144
1550 */
1551const getChangesetInfo = async (pad: PadType, startNum: number, endNum:number, granularity: number) => {
1552 const headRevision = pad.getHeadRevisionNumber();
1553
1554 // calculate the last full endnum
1555 if (endNum > headRevision + 1) endNum = headRevision + 1;
1556 endNum = Math.floor(endNum / granularity) * granularity;
1557
1558 const compositesChangesetNeeded = [];
1559 const revTimesNeeded = [];
1560
1561 // figure out which composite Changeset and revTimes we need, to load them in bulk
1562 for (let start = startNum; start < endNum; start += granularity) {
1563 const end = start + granularity;
1564
1565 // add the composite Changeset we needed
1566 compositesChangesetNeeded.push({start, end});
1567
1568 // add the t1 time we need
1569 revTimesNeeded.push(start === 0 ? 0 : start - 1);
1570
1571 // add the t2 time we need
1572 revTimesNeeded.push(end - 1);
1573 }
1574
1575 // Get all needed db values in parallel.
1576 const composedChangesets:MapArrayType<any> = {};
1577 const revisionDate:number[] = [];
1578 const [lines] = await Promise.all([
1579 getPadLines(pad, startNum - 1),
1580 // Get all needed composite Changesets.
1581 ...compositesChangesetNeeded.map(async (item) => {
1582 const changeset = await exports.composePadChangesets(pad, item.start, item.end);
1583 composedChangesets[`${item.start}/${item.end}`] = changeset;
1584 }),
1585 // Get all needed revision Dates.
1586 ...revTimesNeeded.map(async (revNum) => {
1587 const revDate = await pad.getRevisionDate(revNum);
1588 revisionDate[revNum] = revDate;
1589 }),
1590 ]);
1591
1592 // doesn't know what happens here exactly :/
1593 const timeDeltas = [];
1594 const forwardsChangesets = [];
1595 const backwardsChangesets = [];
1596 const apool = new AttributePool();
1597
1598 for (let compositeStart = startNum; compositeStart < endNum; compositeStart += granularity) {
1599 const compositeEnd = compositeStart + granularity;
1600 if (compositeEnd > endNum || compositeEnd > headRevision + 1) break;
1601
1602 const forwards = composedChangesets[`${compositeStart}/${compositeEnd}`];
1603 const backwards = inverse(forwards, lines.textlines, lines.alines, pad.apool());
1604
1605 mutateAttributionLines(forwards, lines.alines, pad.apool());
1606 mutateTextLines(forwards, lines.textlines);
1607
1608 const forwards2 = moveOpsToNewPool(forwards, pad.apool(), apool);

Callers 1

handleChangesetRequestFunction · 0.85

Calls 11

toJsonableMethod · 0.95
inverseFunction · 0.90
mutateAttributionLinesFunction · 0.90
mutateTextLinesFunction · 0.90
moveOpsToNewPoolFunction · 0.90
getPadLinesFunction · 0.85
getHeadRevisionNumberMethod · 0.80
pushMethod · 0.80
mapMethod · 0.80
getRevisionDateMethod · 0.80
apoolMethod · 0.80

Tested by

no test coverage detected