mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -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 !
112 lines
6.5 KiB
JavaScript
112 lines
6.5 KiB
JavaScript
import Boards from '/models/boards';
|
|
import Cards from '/models/cards';
|
|
import Lists from '/models/lists';
|
|
import Swimlanes from '/models/swimlanes';
|
|
import ScrumSprints from '/models/scrumSprints';
|
|
import ScrumReleases from '/models/scrumReleases';
|
|
import ScrumEvents from '/models/scrumEvents';
|
|
import ScrumDailySnapshots from '/models/scrumDailySnapshots';
|
|
import ScrumHistoryPending from './scrumHistoryPending';
|
|
import { ScrumImportPending } from './scrumImportJournal';
|
|
import { withSnapshotRows, withDailyRows } from './scrumSnapshotStore';
|
|
import { hasRolloverPending } from './scrumRolloverStore';
|
|
const { normalizeScrumTransfer, SCRUM_TRANSFER_FORMAT } = require('/models/lib/scrumTransfer');
|
|
|
|
// Call only after the existing export route has authorized the board and scope.
|
|
// Never export private recovery checkpoints or destination revision counters.
|
|
export async function exportScrumTransfer(boardId, cardIds, listIds, swimlaneIds, scoped = false, includeCustomFields = true) {
|
|
const [board, cards, lists, swimlanes, sprints, releases, events] = await Promise.all([
|
|
Boards.findOneAsync(boardId),
|
|
Cards.find({ boardId, _id: { $in: cardIds }, scrum: { $exists: true } }, { fields: { scrum: 1 } }).fetchAsync(),
|
|
Lists.find({ boardId, _id: { $in: listIds }, scrum: { $exists: true } }, { fields: { scrum: 1 } }).fetchAsync(),
|
|
Swimlanes.find({ boardId, _id: { $in: swimlaneIds }, scrum: { $exists: true } }, { fields: { scrum: 1 } }).fetchAsync(),
|
|
ScrumSprints.find({ boardId }).fetchAsync(), ScrumReleases.find({ boardId }).fetchAsync(), ScrumEvents.find({ boardId }).fetchAsync(),
|
|
]);
|
|
// The transfer carries snapshots whole, their rows included, wherever they
|
|
// are kept (scrumSnapshotStore.js).
|
|
for (let index = 0; index < sprints.length; index += 1) sprints[index] = await withSnapshotRows(sprints[index]);
|
|
if (!board) throw new Error('Board no longer exists');
|
|
if (await ScrumImportPending.findOneAsync(boardId, { fields: { _id: 1 } })) {
|
|
throw new Error('Finish the pending Scrum operation before exporting');
|
|
}
|
|
if (!board.scrum && !cards.length && !lists.length && !swimlanes.length && !sprints.length && !releases.length && !events.length) return null;
|
|
if (await ScrumHistoryPending.findOneAsync(boardId) || sprints.some(s => s.scrumImportPending || hasRolloverPending(s))) {
|
|
throw new Error('Finish the pending Scrum operation before exporting');
|
|
}
|
|
const sprintIds = new Set(); const releaseIds = new Set();
|
|
for (const row of [...cards, ...swimlanes]) {
|
|
if (row.scrum.sprintId) sprintIds.add(row.scrum.sprintId);
|
|
for (const id of row.scrum.pastSprintIds || []) sprintIds.add(id);
|
|
if (row.scrum.releaseId) releaseIds.add(row.scrum.releaseId);
|
|
}
|
|
// Rollover destinations remain structural references, even in a scoped file.
|
|
let changed = true;
|
|
while (changed) {
|
|
changed = false;
|
|
for (const sprint of sprints) if (sprintIds.has(sprint._id) && sprint.rolloverSprintId && !sprintIds.has(sprint.rolloverSprintId)) {
|
|
sprintIds.add(sprint.rolloverSprintId); changed = true;
|
|
}
|
|
}
|
|
const visibleCards = new Set(cardIds); const visibleLists = new Set(listIds);
|
|
const losses = [];
|
|
const clean = record => {
|
|
const { boardId: ignoredBoard, revision, rolloverPending, closedFromRevision, scrumImportPending, reportTotals,
|
|
...data } = record;
|
|
return data;
|
|
};
|
|
const metadata = rows => rows.map(row => ({ _id: row._id, scrum: row.scrum }));
|
|
const transfer = { format: SCRUM_TRANSFER_FORMAT, settings: board.scrum || {}, cards: metadata(cards), lists: metadata(lists), swimlanes: metadata(swimlanes),
|
|
sprints: sprints.filter(s => !scoped || sprintIds.has(s._id)).map(clean),
|
|
releases: releases.filter(r => !scoped || releaseIds.has(r._id)).map(clean),
|
|
events: events.filter(e => !scoped || sprintIds.has(e.sprintId)).map(clean) };
|
|
function filterSnapshot(snapshot, path) {
|
|
snapshot.cards = snapshot.cards.filter(card => {
|
|
if (visibleCards.has(card.cardId) && visibleLists.has(card.listId)) return true;
|
|
losses.push({ path, sourceId: card.cardId, reason: 'card-or-list-not-exported' });
|
|
snapshot.partial = true; return false;
|
|
});
|
|
snapshot.missingEstimates = snapshot.cards.filter(c => c.estimate === null).length;
|
|
snapshot.totalEstimate = snapshot.cards.reduce((sum, c) => sum + (c.estimate ?? 0), 0);
|
|
}
|
|
for (const sprint of transfer.sprints) for (const key of ['startSnapshot', 'closeSnapshot']) {
|
|
if (sprint[key]) filterSnapshot(sprint[key], `sprints.${sprint._id}.${key}`);
|
|
}
|
|
transfer.dailyObservations = [];
|
|
const cursor = ScrumDailySnapshots.rawCollection().find({ boardId,
|
|
sprintId: { $in: transfer.sprints.map(sprint => sprint._id) } },
|
|
{ sort: { capturedAt: 1, _id: 1 }, limit: 10001, batchSize: 1 });
|
|
try {
|
|
// No cap on the cards a day observed (maintainer decision of 2026-10-03);
|
|
// the number of observed days keeps its limit.
|
|
for await (const stored of cursor) {
|
|
if (transfer.dailyObservations.length >= 10000) {
|
|
throw new Error('Daily Scrum history exceeds the native transfer limit');
|
|
}
|
|
const row = await withDailyRows(stored);
|
|
filterSnapshot(row.snapshot, `dailyObservations.${row.sprintId}.${row.day}`);
|
|
const { sprintId, startedAt, day, capturedAt, snapshot, consistency } = row;
|
|
transfer.dailyObservations.push({ sprintId, startedAt, day, capturedAt, snapshot, consistency });
|
|
}
|
|
} finally { await cursor.close(); }
|
|
for (const event of transfer.events) event.followUpCardIds = (event.followUpCardIds || []).filter(id => {
|
|
if (visibleCards.has(id)) return true;
|
|
losses.push({ path: `events.${event._id}.followUpCardIds`, sourceId: id, reason: 'card-not-exported' }); return false;
|
|
});
|
|
if (!includeCustomFields) {
|
|
const references = new Set([transfer.settings.estimateCustomFieldId,
|
|
...transfer.sprints.flatMap(s => [s.startSnapshot?.estimateCustomFieldId, s.closeSnapshot?.estimateCustomFieldId]),
|
|
...transfer.dailyObservations.map(row => row.snapshot.estimateCustomFieldId),
|
|
].filter(Boolean));
|
|
for (const sourceId of references) losses.push({ path: 'customFields', sourceId, reason: 'estimate-field-not-exported' });
|
|
}
|
|
return { transfer: normalizeScrumTransfer(transfer), losses };
|
|
}
|
|
|
|
export function scrumTransferUserIds(transfer) {
|
|
if (!transfer) return [];
|
|
return [...new Set([transfer.settings.productOwnerId, transfer.settings.scrumMasterId,
|
|
...(transfer.settings.developerIds || []),
|
|
...[...transfer.sprints, ...transfer.releases, ...transfer.events].flatMap(row => [row.createdBy, row.updatedBy]),
|
|
].filter(Boolean))];
|
|
}
|