mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
A sprint over 10,000 cards was refused at start and close. With the snapshot rows already outside the sprint document, the rest now is too: - The rollover plan of a close goes to its own collection, scrumRolloverRows, in chunks bounded by rows and bytes; the sprint keeps only rolloverPending: true. A chunk is applied, its cards read at once, and removed; the mark is cleared when none is left. A plan kept in the sprint document before this is still finished as it was. - A Scrum History batch too large for one row is recorded as several rows sharing a batchId, each at most 1,000 records and 3 MB a side. A record is in exactly one row, and undo and redo walk the whole batch, with or without a request ID, so one undo still reverses a whole close. - Daily burndown observations keep their rows in scrumSnapshotRows too. - No 10,000-card limit is left: snapshot inputs, daily capture, scope replay, the daily report and the transfer read every card. Undoing a batch re-hashed its whole History row and sent its whole plan as a selector before every record write, so a 1,500-card undo took four minutes. The row is now checked whole when the operation begins and by its identity fields after that, and the worker check uses the plan's identity and the worker's random id - nothing ever rewrites a pending plan. A 10,500-card sprint closes in 8 s and undoes in 44 s. Thanks to xet7 !
81 lines
4.1 KiB
JavaScript
81 lines
4.1 KiB
JavaScript
const { scrumHistorySelector, assertScrumHistoryOperation } = require('./scrumHistoryOwnership');
|
|
const { rowHashIsValid } = require('../../models/lib/changeHistoryIntegrity');
|
|
const { readScrumHistoryCompletion, saveScrumHistoryCompletion } = require('./scrumHistoryCompletion');
|
|
|
|
// A pending checkpoint must not make an invalidated redo eligible again when
|
|
// its source row is reloaded on retry. Compare identity and immutable evidence,
|
|
// but reject superseded redo independently of the caller's captured value.
|
|
function verifyScrumHistorySource(current, row, direction) {
|
|
if (!rowHashIsValid(current)) throw new Error('Scrum History finalization conflict');
|
|
verifyScrumHistorySourceState(current, row, direction);
|
|
}
|
|
// The same, without re-hashing the row's content: for the check before each
|
|
// write of an operation whose row was verified whole when it began. A batch
|
|
// of a thousand records hashed its row a thousand times.
|
|
function verifyScrumHistorySourceState(current, row, direction) {
|
|
if (!current || current._id !== row._id ||
|
|
current.integrityHash !== row.integrityHash || current.boardId !== row.boardId ||
|
|
current.userId !== row.userId || !!current.superseded !== !!row.superseded ||
|
|
(direction === 'redo' && current.superseded)) {
|
|
throw new Error('Scrum History finalization conflict');
|
|
}
|
|
}
|
|
|
|
// The timeline events have already been acknowledged. Keep the board journal
|
|
// until the original row's undo/redo state and durable completion are verified,
|
|
// then delete only this operation's checkpoint. Retry must not move undoneAt.
|
|
async function finishScrumHistory({ history, pending, completions, row, journal, now = () => new Date() }) {
|
|
const identity = scrumHistorySelector(journal);
|
|
const fail = () => { throw new Error('Scrum History finalization conflict'); };
|
|
if (!['undo', 'redo', 'restore'].includes(journal.direction) ||
|
|
typeof journal.operationId !== 'string' || !journal.operationId ||
|
|
journal.rowId !== row._id || journal._id !== row.boardId) fail();
|
|
const owned = () => assertScrumHistoryOperation(pending, journal);
|
|
const verify = current => verifyScrumHistorySource(current, row, journal.direction);
|
|
const cleanup = async () => {
|
|
// A verified receipt can reconcile an absent checkpoint or a successor. It
|
|
// proves this operation finished, not that the board still has its values.
|
|
const checkpoint = await pending.findOneAsync({ _id: journal._id });
|
|
if (!checkpoint || checkpoint.operationId !== journal.operationId) return;
|
|
await owned();
|
|
let cleanupError;
|
|
try { await pending.removeAsync(identity); }
|
|
catch (error) { cleanupError = error; }
|
|
const remaining = await pending.findOneAsync({ _id: journal._id });
|
|
if (remaining?.operationId === journal.operationId) {
|
|
throw cleanupError || new Error('Scrum History cleanup unconfirmed');
|
|
}
|
|
};
|
|
if (await readScrumHistoryCompletion(completions, journal, row)) {
|
|
await cleanup();
|
|
return;
|
|
}
|
|
await owned();
|
|
let current = await history.findOneAsync(row._id);
|
|
verify(current);
|
|
if (journal.direction !== 'restore') {
|
|
const undone = journal.direction === 'undo';
|
|
if (current.undone !== undone) {
|
|
await owned();
|
|
const count = await history.updateAsync({ _id: row._id, boardId: row.boardId,
|
|
userId: row.userId, integrityHash: row.integrityHash,
|
|
superseded: Object.hasOwn(current, 'superseded') ? current.superseded : { $exists: false },
|
|
undone: current.undone }, {
|
|
$set: { undone, undoneAt: undone ? now() : null },
|
|
});
|
|
if (count !== 1) fail();
|
|
}
|
|
// Do not equate a matched update with a persisted final state. This also
|
|
// catches a concurrent change before discarding the recovery evidence.
|
|
current = await history.findOneAsync(row._id);
|
|
verify(current);
|
|
if (current.undone !== undone || (undone
|
|
? !(current.undoneAt instanceof Date) || !Number.isFinite(current.undoneAt.getTime())
|
|
: current.undoneAt !== null)) fail();
|
|
}
|
|
await owned();
|
|
await saveScrumHistoryCompletion(completions, journal, row, now);
|
|
await cleanup();
|
|
}
|
|
module.exports = { finishScrumHistory, verifyScrumHistorySource, verifyScrumHistorySourceState };
|