Files
wekan/models/lib/importDeadline.js
T
Lauri Ojansivu 14a43da557 Large Jira exports import, and an existing board can be saved as a board template.
From IRC: a Jira import of 25 issues worked and one of 858 failed. The
import boundary refused any document over 250,000 values, and a Jira
search export carries some 250 per issue even without comments - mostly
null custom fields, avatar URLs and status categories - so it stopped at
under 1,000 issues, about 6 MB. The refusal was a plain Error, which the
import page showed as "Internal server error". The cap is now four
million values; a file over it is refused as import-too-large, which the
page translates, with the limit as the reason. The import deadline was a
flat two minutes whatever the file held; it is now WEKAN_IMPORT_TIMEOUT_MS
plus half a second per record (models/lib/importDeadline.js), on the
server and in the import page's watchdog alike. The Jira creator also
collected the file's issue keys once per issue, which was quadratic.

"Is there a way to convert an existing board into a template?" There was
not: a board template could only be built inside the Templates board.
Board menu / Save as Template (saveBoardAsTemplate) copies the board as a
template board, private with the creator as its one member, and adds the
linked card in the user's Templates / Board Templates swimlane that makes
it a template. Board admins only, as Copy Board, and not offered on a
board that already is a template.

The new import-too-large string is translated into every language; the
low-confidence ones are ace, ak, an, ay, bm, bo, bua, chr, csb, cv, dz, ee,
ff, fj, fo, fur, gn, gv, haw, hsb, iu, kl, kok, ks, kw, lg, lld, nah, nap,
nd, rm, rup, sah, sc, scn, se, ss, tig, tlh, to, ve, ve-PP, ve-CC, vo, wa,
wa-RR, wal, wo, wuu-Hans and zgh.

Thanks to xet7 !

Fixes #6792.
2026-10-21 15:30:32 +03:00

40 lines
1.7 KiB
JavaScript

// How long one board import may take before it is stopped (#6792).
//
// The deadline used to be a flat two minutes whatever the file held: a Jira
// export of 25 issues imported, one of 858 ran out of time halfway - every
// issue is a card with its comments, checklists and attachments, and the
// writer was aborted while still writing. The deadline is there to free a
// client from a HUNG import, not to cap a large one, so it grows with the
// number of records the document carries.
//
// Shared by the server's deadline (models/import.js importBoard) and the
// import page's watchdog (client/components/import/import.js), so the two
// agree on how long a given file may take.
// Time allowed for each record on top of the base deadline.
const IMPORT_MS_PER_RECORD = 500;
// The records a document carries: the length of an array (CSV rows, a GitHub
// issue list), the lines of a text export, or the sum of the top-level arrays
// of an object (Jira's issues, WeKan's and Trello's cards, lists, checklists
// and actions). Anything else counts as nothing and keeps the base deadline.
function importRecordCount(doc) {
if (Array.isArray(doc)) return doc.length;
if (typeof doc === 'string') return doc.split('\n').length;
if (!doc || typeof doc !== 'object') return 0;
let count = 0;
for (const key of Object.keys(doc)) {
if (Array.isArray(doc[key])) count += doc[key].length;
}
return count;
}
// `baseMs` is WEKAN_IMPORT_TIMEOUT_MS (or its default); zero or less still
// means no deadline at all, as it always has.
function importDeadlineFor(baseMs, doc) {
if (!(baseMs > 0)) return baseMs;
return baseMs + importRecordCount(doc) * IMPORT_MS_PER_RECORD;
}
export { importRecordCount, importDeadlineFor, IMPORT_MS_PER_RECORD };