Files
wekan/tests/openIssuesVerifiedFromCode.test.cjs
T
Lauri Ojansivu d56bb34490 Make large boards fast on 8 GB: load only what is visible, stop re-running every minicard, and stream big attachments.
On a seeded board of 4,000 cards, 12,000 comments, 20,000 checklist items
and 32,000 activities, served from FerretDB with SQLite as the Snap is:
closing a card took about 4 s and now takes 0.1 s, the board finished
loading in 17.6 s and now in 6.2 s, a card open re-ran about 7,700
computations and now about 1,000, and FerretDB used 13 s of CPU and 724 MB
while the board opened, now 3 s and 280 MB.

- The client data cache queued one more stop callback each time a helper
  re-ran, and every check asked Tracker for dependents, which on close was
  710 walks of 3 ms; there is now one callback per computation and key and
  one timer per key (imports/lib/dataCache.js).
- Opening a card writes the user's last-viewed card, and avatars, @mentions,
  list and swimlane headers read the whole user, so everything re-ran; they
  read only the fields they show. The comment, checklist and subtask indexes
  were one object every minicard depended on and are now per card
  (imports/lib/keyedGroupIndex.js).
- The lazy card window kept a full copy of every card of a list per window;
  it keeps the id and the sort keys, runs its id query once instead of five
  times, and sends comment text only when minicards show comments
  (server/publications/cardsWindow.js, models/lib/cardWindowFields.js).
  Comment reactions and legacy attachment lookups come with the opened card
  only.
- Attachment downloads honour Range for filesystem, GridFS and cloud
  storage (206, 416, If-Range); uploads to cloud storage are spooled to a
  temporary file and streamed instead of gathered into one Buffer; the API
  copy checks the size limit before reading; the legacy attachment
  migration streams, and no longer stores "[object Promise]" as a file; the
  board export no longer concatenates buffers quadratically.

The FerretDB fork pushes dotted-path filters such as meta.cardId down to
SQLite (they were each a full scan) and decodes only the fields a count
filters on. docs/Features/Admin-Panel/Problems/Large-Boards.md describes how
a large board loads and how to size a server with 8 GB of RAM.

Thanks to markusst1982 and xet7 !

Fixes #6745.
2026-10-09 13:28:08 +03:00

130 lines
6.8 KiB
JavaScript

'use strict';
// Two open issues that turned out to be answered by the code as it stands.
// Run: node tests/openIssuesVerifiedFromCode.test.cjs
//
// Both were in the CHANGELOG's TODO Later list as "needs the running app", and
// both are decided by files that can simply be read - so they are pinned here
// rather than left in a backlog:
//
// #5052 ".eml attachments cannot be opened" - a blank page in the browser
// and nothing usable in Thunderbird, after a board was copied.
// #5081 "Correct display of owner, member and assignee on mini cards" -
// owner on the very left, members next, assignees on the very right,
// wrapping to a second right-aligned row when they do not fit.
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const Module = require('module');
const repoRoot = path.resolve(__dirname, '..');
const read = f => fs.readFileSync(path.join(repoRoot, f), 'utf8');
const origResolve = Module._resolveFilename;
Module._resolveFilename = function(request, ...rest) {
if (request === '/imports/lib/fileNameDisplay') {
return path.join(repoRoot, 'imports', 'lib', 'fileNameDisplay.js');
}
return origResolve.call(this, request, ...rest);
};
const { sanitizeUploadFileName } = require('../models/lib/uploadFileName.js');
let passed = 0;
function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
console.log('openIssuesVerifiedFromCode:');
// ── #5052: .eml attachments ──────────────────────────────────────────────────
test('#5052: an .eml keeps its name through upload and through a board copy', () => {
// The mechanism that could produce "cannot open .eml": a mangled name. An
// unknown MIME used to append .bin (#6589), and Thunderbird will not open a
// .bin. Every type a mail file arrives as now keeps the extension.
for (const type of ['message/rfc822', 'application/octet-stream', '', null]) {
assert.strictEqual(sanitizeUploadFileName('mail.eml', type), 'mail.eml',
`an .eml sent as ${JSON.stringify(type)} must stay an .eml`);
}
// The copy path runs the same function, so a copied board's attachments are
// named like the originals.
const store = read('models/lib/fileStoreStrategy.js');
const copy = store.slice(store.indexOf('export const copyFile'));
assert.ok(/sanitizeUploadFileName\(fileObj\.name, fileObj\.type\)/.test(copy.slice(0, 1200)),
'copyFile names the copy with the same rule the upload used');
});
test('#5052: an .eml is served as a download, not rendered in the browser', () => {
// The other mechanism: served inline, a browser shows a blank page for a type
// it cannot render. message/rfc822 is neither in the dangerous list nor the
// safe-inline one, so it takes the "unknown types" branch - which forces the
// download with the file's own name.
const server = read('server/routes/universalFileServer.js');
const lists = server.slice(server.indexOf('const dangerousTypes'), server.indexOf('const isSvg'));
assert.ok(!/message\/rfc822/.test(lists),
'message/rfc822 is in neither list, which is what sends it down the fallback');
const fallback = server.slice(server.indexOf('// Unknown types: force download as fallback'));
const branch = fallback.slice(0, fallback.indexOf('\n }'));
assert.ok(/Content-Type', 'application\/octet-stream'/.test(branch), 'downloaded, not rendered');
assert.ok(/buildContentDispositionHeader\('attachment'/.test(branch), 'as an attachment');
assert.ok(/sanitizeFilenameForHeader\(fileObj\.name\)/.test(branch),
'under its own name, so Thunderbird sees an .eml');
});
test('#5052: an attachment whose recorded path is wrong is still found', () => {
// And the third: the file is there under a name the database does not know.
// Reading, renaming and deleting all go through the same search (#6589).
const store = read('models/lib/fileStoreStrategy.js');
assert.ok(/resolveExistingPath\(\)/.test(store));
// #6745: getReadStream takes an optional byte range now.
const getReadStream = store.slice(store.indexOf(' getReadStream(range) {',
store.indexOf('candidatePaths()')));
assert.ok(/this\.resolveExistingPath\(\)/.test(getReadStream.slice(0, 300)));
});
// ── #5081: the minicard avatar row ───────────────────────────────────────────
test('#5081: owner on the left, members next, assignees on the right', () => {
// The request, in the reporter's words: "Owner is on the very left, followed
// by members (if there are any) and on the very right there are the
// assignees."
//
// That is what the current markup and CSS produce, and the reason is the
// float: three siblings that float to the inline end are laid out RIGHT to
// left in DOM order. So DOM order assignees, members, creator renders as
// creator | members | assignees, left to right.
const jade = read('client/components/cards/minicard.jade');
const assignees = jade.indexOf('.minicard-assignees');
const members = jade.indexOf('.minicard-members');
const creator = jade.indexOf('.minicard-creator');
assert.ok(assignees !== -1 && members !== -1 && creator !== -1, 'all three groups exist');
assert.ok(assignees < members && members < creator,
'DOM order assignees, members, creator - which floats render in reverse');
const css = read('client/components/cards/minicard.css');
const rule = css.slice(css.indexOf('.minicard .minicard-members,'));
const block = rule.slice(0, rule.indexOf('}'));
assert.ok(/float:\s*inline-end/.test(block),
'they float to the inline end, which is what puts the creator leftmost');
});
test('#5081: a row that does not fit wraps, still right-aligned', () => {
// "If it does not fit into one row or get to close i would put the assignees
// in a new line but still right aligned." Floated avatars do that by
// themselves - each avatar floats too, so the group wraps within the card.
const css = read('client/components/cards/minicard.css');
const avatarRule = css.slice(css.indexOf('.minicard .minicard-members .member,'));
const block = avatarRule.slice(0, avatarRule.indexOf('}'));
assert.ok(/float:\s*inline-end/.test(block), 'each avatar floats to the inline end');
assert.ok(/margin-bottom/.test(block), 'with room between the wrapped rows');
});
test('#5081: an empty group takes no space (negative)', () => {
// "members (if there are any)": an empty members or assignees container must
// not leave a gap where the group would have been.
const css = read('client/components/cards/minicard.css');
assert.ok(/\.minicard \.minicard-members:empty,\s*\n\.minicard \.minicard-assignees:empty \{\s*\n\s*display: none;/.test(css),
'empty groups are display:none');
});
console.log(`\nopenIssuesVerifiedFromCode: ${passed} tests passed`);