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 !
48 lines
2.5 KiB
JavaScript
48 lines
2.5 KiB
JavaScript
const { createHash } = require('node:crypto');
|
|
const { sprintSnapshot, DEFAULT_SCRUM_SETTINGS } = require('../../models/lib/scrum');
|
|
function dailyObservationId(sprintId, startedAt, day) {
|
|
return createHash('sha256').update(JSON.stringify([sprintId, new Date(startedAt).toISOString(), day])).digest('hex');
|
|
}
|
|
|
|
// Observations are recorded at their actual capture time. Never backfill a
|
|
// missing day with today's state or replace an earlier observation on retry.
|
|
// `rows`, when given, stores the snapshot's rows outside the observation
|
|
// (server/lib/scrumSnapshotStore.js) and returns its header; `discard` forgets
|
|
// them when another capture of the same day won.
|
|
async function captureDailySprint({ sprint, cards, lists, snapshots, at = new Date(), rows = null, discard = null }) {
|
|
if (sprint.scrumImportPending || sprint.state !== 'active' || !sprint.startSnapshot) return { skipped: true };
|
|
const start = new Date(sprint.startSnapshot.at);
|
|
if (!Number.isFinite(start.getTime()) || !Number.isFinite(at.getTime()) || at < start) {
|
|
throw new Error('Invalid daily Scrum observation timestamp');
|
|
}
|
|
const policy = sprint.startSnapshot;
|
|
if (!['poker', 'customField'].includes(policy.estimateSource) ||
|
|
!['dueComplete', 'doneLists'].includes(policy.completionPolicy) || !policy.unit) {
|
|
throw new Error('Daily Scrum observation requires the recorded sprint policy');
|
|
}
|
|
const settings = { ...DEFAULT_SCRUM_SETTINGS,
|
|
estimateSource: policy.estimateSource, estimateCustomFieldId: policy.estimateCustomFieldId,
|
|
estimateUnit: policy.unit, completionPolicy: policy.completionPolicy,
|
|
workingDays: policy.workingDays || DEFAULT_SCRUM_SETTINGS.workingDays };
|
|
const day = at.toISOString().slice(0, 10);
|
|
const epoch = start.toISOString();
|
|
const _id = dailyObservationId(sprint._id, epoch, day);
|
|
const document = { _id, boardId: sprint.boardId, sprintId: sprint._id,
|
|
startedAt: start, day, capturedAt: at, consistency: 'observed',
|
|
snapshot: sprintSnapshot(cards, settings, lists, at) };
|
|
if (policy.partial) document.snapshot.partial = true;
|
|
if (rows) document.snapshot = await rows({ boardId: sprint.boardId, sprintId: sprint._id, kind: 'daily', snapshot: document.snapshot });
|
|
try {
|
|
await snapshots.insertAsync(document);
|
|
return { captured: true };
|
|
} catch (error) {
|
|
if (error.code === 11000) {
|
|
if (discard) await discard({ sprintId: sprint._id, kind: 'daily', at });
|
|
return { captured: false };
|
|
}
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
module.exports = { captureDailySprint, dailyObservationId };
|