Files
wekan/client/lib/currentUserWith.js
Lauri Ojansivu 6d5f24ee27 Large board: read only the user fields each card and list needs.
Opening a card writes the user document (profile.cardLastViews, #3078). The
board view (Utils.storedBoardView and allowBoardView, which every list's card
loop reads) and the helpers every minicard runs read the WHOLE user document,
so that one write re-ran every list's card loop, and Blaze then re-evaluated
every minicard: 37,452 Tracker invalidations for one card open on a 40-card
board. Measured in the running app, it is now 390.

client/lib/currentUserWith.js reads the current user with only the named
fields; minimongo re-runs a field-limited query only when a projected field
changes. The board view, feature preview, unread comments, folds, drag
handles, label text, dependency layers, date format, week number, mobile mode
and the admin-only custom field check now use it. setCardLastViewed $sets one
entry instead of rewriting the whole map, which is also capped at 5,000.

Thanks to markusst1982 and xet7 !

Fixes #6745.
2026-10-07 03:08:48 +03:00

19 lines
912 B
JavaScript

import { Meteor } from 'meteor/meteor';
const { userFieldsProjection } = require('/models/lib/userFieldsProjection');
// #6745: the current user with ONLY the given fields (plus _id), or null when
// nobody is logged in or the document has not arrived yet - the same two cases
// Meteor.user() returns null for. The document keeps the Users helpers, so
// `currentUserWith(['profile.showWeekOfYear']).isShowWeekOfYear()` still works.
//
// Use it in helpers that run once per minicard. The calling computation then
// re-runs only when one of these fields changes, not on every write to the user
// document - opening a card is one such write. See
// models/lib/userFieldsProjection.js.
export function currentUserWith(paths) {
const userId = Meteor.userId();
if (!userId) return null;
const fields = userFieldsProjection(paths);
return Meteor.users.findOne(userId, fields ? { fields } : {}) || null;
}