Files
wekan/tests/cardsWindowSnapshot.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

44 lines
2.1 KiB
JavaScript

'use strict';
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const test = require('node:test');
const source = fs.readFileSync(
path.resolve(__dirname, '../server/publications/cardsWindow.js'),
'utf8',
);
test('the limited card window refreshes snapshots instead of live-observing', () => {
const start = source.indexOf('// The window\'s cards.');
const end = source.indexOf('// The window\'s comments', start);
const child = source.slice(start, end);
assert.match(child, /\{ sort: sortOpt, limit: lim \},\s*false/);
assert.doesNotMatch(child, /\{ sort: sortOpt, limit: lim \},\s*true/);
assert.match(child, /publication\.added\('cards', _id, fields\)/);
assert.match(child, /publication\.changed\('cards', card\._id, card\.fields\)/);
assert.match(child, /publication\.removed\('cards', cardId\)/);
// #6745: the membership observer watches WHICH cards match and their sort
// keys only - a full copy of every card of the list per window held the
// whole board in server memory - and a second observer watches every field
// of the cards that ARE in the window, so an edit still re-reads it.
assert.match(child, /Cards\.find\(windowSel\(board\), \{\s*fields: windowOrderFields\(sortOpt\),\s*\}\)\.observeChangesAsync/);
assert.doesNotMatch(child, /Cards\.find\(windowSel\(board\)\)\.observeChangesAsync/);
assert.match(child, /Cards\.find\(\{ _id: \{ \$in: ids \} \}\)\.observeChangesAsync/);
assert.match(child, /await watchWindowContent\(cards\.map\(card => card\._id\)\)/);
assert.match(child, /if \(contentHandle\) contentHandle\.stop\(\);/);
assert.doesNotMatch(child, /setInterval/);
assert.match(child, /observerHandle\.stop\(\)/);
assert.match(child, /return null;/);
});
test('the client re-subscribes with limit, filter and sort changes', () => {
const client = fs.readFileSync(
path.resolve(__dirname, '../client/components/lists/listBody.js'),
'utf8',
);
assert.match(client, /subscribe\('boardCardsWindow', list\.boardId, mongoSelector, sortBy, limit\)/);
});