Files
wekan/models/server/createWorkbook.js
T
xet7 41cd166358 Stream board exports (JSON, CSV/TSV, Excel) with bounded memory
The board export routes buffered the entire board in memory before sending:
JSON export built one object with every card, comment, activity, checklist and
base64 attachment; CSV called that same build(); Excel additionally loaded data
it never renders (activities/checklists/subtasks/rules) and did O(n^2)
result.cards.find() lookups. On big boards this peaked at gigabytes and could
exceed V8's max string length.

Now:
- Exporter.buildStream(res) writes the JSON document straight to the response a
  document at a time from raw Mongo cursors, encoding each attachment file to
  base64 in 3-byte-aligned chunks. Same _format/keys, so import round-trips.
- Exporter.buildCsvStream(res) keeps only the small lookup tables in memory and
  streams cards from a cursor, writing one CSV/TSV row at a time.
- ExporterExcel uses the exceljs streaming WorkbookWriter, committing each row
  to the response, drops the unused collections, and resolves parent/comment
  card titles via an id->title map instead of scanning all cards.
Peak memory stays flat regardless of board size.
2026-07-10 22:57:40 +03:00

19 lines
635 B
JavaScript

import Excel from '@wekanteam/exceljs';
export const createWorkbook = function() {
return new Excel.Workbook();
};
// Streaming workbook writer: flushes rows straight to `stream` (the HTTP
// response) as they are committed, instead of holding the whole workbook in
// memory. Used by board Excel export so a board with thousands of cards exports
// with bounded RAM. useStyles/useSharedStrings keep the styled output identical
// to the in-memory Workbook.
export const createWorkbookWriter = function(stream) {
return new Excel.stream.xlsx.WorkbookWriter({
stream,
useStyles: true,
useSharedStrings: true,
});
};