mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -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 !
65 lines
3.3 KiB
JavaScript
65 lines
3.3 KiB
JavaScript
// A sprint close's rollover plan, outside the sprint document (maintainer
|
|
// decision of 2026-10-03: sprints with no card cap). The close writes one row
|
|
// per card - its revision, and its Scrum metadata before and after - in chunks
|
|
// here, then marks the sprint `rolloverPending: true`; the rollover applies a
|
|
// chunk and removes it, and clears the mark when none is left. A plan kept in
|
|
// the sprint document before this (an array) is still finished as it was.
|
|
import { Meteor } from 'meteor/meteor';
|
|
import { Mongo } from 'meteor/mongo';
|
|
import { ensureIndex } from '/server/lib/mongoStartup';
|
|
const { calculateObjectSize } = require('bson');
|
|
const { SNAPSHOT_CHUNK } = require('/models/lib/scrumSnapshotRows');
|
|
// A card's Scrum metadata may carry long texts, so a chunk is bounded by bytes
|
|
// as well as by rows.
|
|
const CHUNK_BYTES = 4 * 1024 * 1024;
|
|
|
|
export const ScrumRolloverRows = new Mongo.Collection('scrumRolloverRows');
|
|
ScrumRolloverRows.deny({ insert: () => true, update: () => true, remove: () => true });
|
|
Meteor.startup(async () => {
|
|
await ensureIndex(ScrumRolloverRows, { boardId: 1 });
|
|
await ensureIndex(ScrumRolloverRows, { sprintId: 1, chunk: 1 });
|
|
await ensureIndex(ScrumRolloverRows, { sprintId: 1, 'rows.cardId': 1 });
|
|
const Boards = require('/models/boards').default;
|
|
Boards.after.remove(async (_userId, board) => { await ScrumRolloverRows.rawCollection().deleteMany({ boardId: board._id }); });
|
|
});
|
|
|
|
// A sprint with a rollover still to finish, in either form.
|
|
export const ROLLOVER_PENDING = { $or: [{ rolloverPending: true }, { 'rolloverPending.0': { $exists: true } }] };
|
|
export const hasRolloverPending = sprint => sprint?.rolloverPending === true ||
|
|
(Array.isArray(sprint?.rolloverPending) && sprint.rolloverPending.length > 0);
|
|
|
|
// Write the plan before the sprint is marked. Called under the board's Scrum
|
|
// lock with the sprint still active, so any chunk of it is left over from a
|
|
// close that never marked the sprint, and is replaced.
|
|
export async function storeRolloverPlan({ boardId, sprintId, rows }) {
|
|
const raw = ScrumRolloverRows.rawCollection();
|
|
await raw.deleteMany({ sprintId });
|
|
let chunk = 0, part = [], bytes = 0;
|
|
const flush = async () => {
|
|
await raw.insertOne({ _id: `${sprintId}:rollover:${chunk}`, boardId, sprintId, chunk, rows: part });
|
|
chunk += 1; part = []; bytes = 0;
|
|
};
|
|
for (const row of rows) {
|
|
const cost = calculateObjectSize(row);
|
|
if (part.length && (part.length >= SNAPSHOT_CHUNK || bytes + cost > CHUNK_BYTES)) await flush();
|
|
part.push(row); bytes += cost;
|
|
}
|
|
if (part.length) await flush();
|
|
}
|
|
|
|
// The next chunk still to apply, or null.
|
|
export function nextRolloverChunk(sprintId) {
|
|
return ScrumRolloverRows.rawCollection().findOne({ sprintId }, { sort: { chunk: 1 } });
|
|
}
|
|
export function finishRolloverChunk(chunk) {
|
|
return ScrumRolloverRows.rawCollection().deleteOne({ _id: chunk._id });
|
|
}
|
|
|
|
// Whether the pending rollover touches a card this reader may see.
|
|
export async function rolloverTouches(sprint, cardIds) {
|
|
if (Array.isArray(sprint.rolloverPending)) return sprint.rolloverPending.some(row => cardIds.has(row.cardId));
|
|
if (sprint.rolloverPending !== true) return false;
|
|
return !!await ScrumRolloverRows.rawCollection().findOne({ sprintId: sprint._id, 'rows.cardId': { $in: [...cardIds] } },
|
|
{ projection: { _id: 1 } });
|
|
}
|