mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
Found running the Email view's browser test against the production bundle: once in eight runs, searching for text that matches nothing still listed the previous search's card. Both views subscribe in an autorun, so a new search's subscription starts before the old one stops, and both published their page's ids into ONE shared index document; DDP's merge box shows the older subscription's value while both exist, so whenever the old one stopped late the new search showed the old rows. Each request now has its own index, keyed by its arguments (models/lib/reportPageIndex.js reportPageKey), built the same way on the server and the client (emailViewPageArgs normalizes the Email view's folder, page and search), and each view reads only the index of the request it made. Admin Panel / Problems stops its subscription before the next one, so its requests never overlap and keep a fixed id. Tests: tests/reportPageKey.test.cjs (one id per request, server and client agree, no autorun view reads a shared id); emailView and publicBoardsPage pin the keyed ids. Against a rebuilt bundle the Email view test passed 8 of 8, and with the Public Boards, Chat, Version Control and import specs 30 of 30. Thanks to xet7 !
41 lines
2.3 KiB
JavaScript
41 lines
2.3 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';
|
|
|
|
// One index per REQUEST, not per report, for a view that subscribes in an
|
|
// autorun. Typing a new search starts the new subscription before the old one
|
|
// stops, and both publish an index; under one shared id DDP's merge box shows
|
|
// the OLDER subscription's ids until it is gone, so a search could keep the
|
|
// previous search's rows (seen in the Email view: "nothing-matches-this"
|
|
// still listing one card). Keyed by the subscription's arguments, each search
|
|
// has its own index and the view reads only the one it asked for. Server and
|
|
// client build the key with this same function.
|
|
export function reportPageKey(reportId, args) {
|
|
return `${reportId}:${JSON.stringify(args)}`;
|
|
}
|
|
|
|
// 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 });
|
|
}
|