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 !
66 lines
3.2 KiB
JavaScript
66 lines
3.2 KiB
JavaScript
import { Meteor } from 'meteor/meteor';
|
|
import { EJSON } from 'meteor/ejson';
|
|
import { SyncedCron } from '/server/cron/syncedCron';
|
|
import Cards from '/models/cards';
|
|
import Boards from '/models/boards';
|
|
import Lists from '/models/lists';
|
|
import ScrumSprints from '/models/scrumSprints';
|
|
import ScrumDailySnapshots from '/models/scrumDailySnapshots';
|
|
import { ScrumImportPending } from '/server/lib/scrumImportJournal';
|
|
const { captureDailySprint } = require('/server/lib/scrumDailyCapture');
|
|
import { storeSnapshot, discardRows } from '/server/lib/scrumSnapshotStore';
|
|
|
|
export async function captureOneSprint(sprint) {
|
|
if (sprint.scrumImportPending) return { skipped: true };
|
|
if (sprint.state !== 'active') return { skipped: true };
|
|
if (!sprint.startSnapshot) return { skipped: true };
|
|
if (await ScrumImportPending.findOneAsync(sprint.boardId, { fields: { _id: 1 } })) return { skipped: true };
|
|
const at = new Date(), day = at.toISOString().slice(0, 10);
|
|
if (await ScrumDailySnapshots.findOneAsync({ sprintId: sprint._id, boardId: sprint.boardId,
|
|
startedAt: new Date(sprint.startSnapshot.at), day }, { fields: { _id: 1 } })) return { skipped: true };
|
|
const [cards, lists] = await Promise.all([
|
|
Cards.find({ boardId: sprint.boardId, 'scrum.sprintId': sprint._id }, {
|
|
fields: { listId: 1, archived: 1, dueComplete: 1, 'poker.estimation': 1, customFields: 1 } }).fetchAsync(),
|
|
Lists.find({ boardId: sprint.boardId }, { fields: { scrum: 1 } }).fetchAsync(),
|
|
]);
|
|
const current = await ScrumSprints.findOneAsync(sprint._id);
|
|
if (!current || current.state !== 'active' || !EJSON.equals(current.startSnapshot, sprint.startSnapshot)) return { skipped: true };
|
|
if (await ScrumImportPending.findOneAsync(sprint.boardId, { fields: { _id: 1 } })) return { skipped: true };
|
|
// The day's rows go to their own chunks, like a sprint's snapshots: no card
|
|
// cap (maintainer decision of 2026-10-03).
|
|
const result = await captureDailySprint({ sprint, cards, lists, snapshots: ScrumDailySnapshots, at: new Date(),
|
|
rows: storeSnapshot, discard: discardRows });
|
|
// Cover deletion during the capture as well as the normal board-delete hook.
|
|
if (!await Boards.findOneAsync(sprint.boardId, { fields: { _id: 1 } })) {
|
|
await ScrumDailySnapshots.removeAsync({ boardId: sprint.boardId });
|
|
return { skipped: true };
|
|
}
|
|
return result;
|
|
}
|
|
|
|
export async function scanScrumDailySnapshots() {
|
|
let lastId;
|
|
while (true) {
|
|
const sprints = await ScrumSprints.find({ state: 'active', ...(lastId ? { _id: { $gt: lastId } } : {}) },
|
|
{ sort: { _id: 1 }, limit: 50 }).fetchAsync();
|
|
if (!sprints.length) return;
|
|
for (const sprint of sprints) {
|
|
try {
|
|
await captureOneSprint(sprint);
|
|
} catch (error) {
|
|
// Failure leaves a visible missing day; never synthesize an observation.
|
|
console.error('scrumDailySnapshots: capture failed', sprint._id, error.message);
|
|
}
|
|
}
|
|
lastId = sprints[sprints.length - 1]._id;
|
|
}
|
|
}
|
|
|
|
Meteor.startup(() => {
|
|
Boards.after.remove(async (_userId, board) => {
|
|
await ScrumDailySnapshots.removeAsync({ boardId: board._id });
|
|
});
|
|
SyncedCron.add({ name: 'wekan-scrum-daily-snapshots',
|
|
schedule: parser => parser.text('every 15 minutes'), job: scanScrumDailySnapshots });
|
|
});
|