Files
wekan/models/lib/reportPageIndex.js
T
Lauri Ojansivu c1add5bc5e Paginate the admin lists honestly: one page of ten, index-backed.
Admin Panel / People showed the admin on every one of its 578 pages, and
Admin Panel / Problems / Broken cards was one endless page under a pager that
said "1 / 1". Same bug in two shapes: the pane subscribes to a publication
that sends exactly one page, then reads the page back out of minimongo - which
holds far more than the page. The logged-in user's own record is always there
(accounts publishes it), and so is every card of every board the admin has
opened. A plain find(query) cannot tell those apart from the page.

So the server names the page. getPeoplePageIds returns the ids of the People
page with the publication's own selector, sort and window; the Broken cards,
Cards and Boards report publications send the ids of the page they just sent
alongside it. Both panes render that list, in that order, and nothing else.

Every paginated page in WeKan now loads ten rows at a time, from one constant -
TABLE_PAGE_ROWS_PER_PAGE - including the pages that draw a pager of their own:
the reports and event streams, the four People panes, Translation, the search
pages and the archive. docs/Design/Page/Table.md records the rule and its two
deliberate exceptions.

And the counting behind those pagers is index-backed. Every count already asks
the database for a count rather than fetching the rows, but several counted and
paged on unindexed fields: People sorts users newest-first, so on an instance
with 14000 users each page of ten sorted all 14000 first. Broken cards asks an
$or over boardId/swimlaneId/listId/type, which uses no index at all unless
every branch has one. The missing indexes are created at startup by the
idempotent ensureIndex, so an upgrade adds them by itself.

Thanks to xet7 !
2026-07-27 23:39:37 +03:00

29 lines
1.6 KiB
JavaScript

// WHICH documents one page of an Admin Panel report consists of.
//
// The paginated reports (Problems / Broken cards, Cards, Boards) publish exactly
// one page: server-side search, sort, limit and skip, sent with `this.added`. The
// pane then reads that page back out of minimongo - and minimongo holds far more
// than the page. Every card of every board the admin has opened is in there, every
// board they are a member of, everything the previous report left behind. A plain
// `Cards.find({})` cannot tell those apart from the page, so Broken cards rendered
// hundreds of rows while its pager - which counts on the server - correctly said
// "1 / 1". Admin Panel / People had the same bug in its own shape: the admin's own
// user record is always in minimongo, so the admin appeared on all 578 pages.
//
// The publication knows the answer, so it says it: alongside the page it sends one
// small document listing the page's ids IN THE ORDER IT SORTED THEM. The pane
// renders that list (see docsByIds in models/lib/tablePage.js) and nothing else.
// It is a DDP-only collection - no server-side Mongo collection is created for it;
// the client declares a Mongo.Collection with this name to receive it.
export const REPORT_PAGE_COLLECTION = 'report_pages';
// Send the index for `reportId` from inside a publication (`this`).
// Documents without an `_id` are skipped rather than published as a null id.
export function publishReportPage(publication, reportId, docs) {
const ids = (Array.isArray(docs) ? docs : [])
.map(doc => doc && doc._id)
.filter(Boolean);
publication.added(REPORT_PAGE_COLLECTION, reportId, { ids });
}