Move every Users.findOne() to the ReactiveCache

This commit is contained in:
Martin Filser 2023-01-15 01:11:16 +01:00
parent bf48d4371c
commit 6e1ef3d94a
35 changed files with 175 additions and 125 deletions

View file

@ -166,14 +166,7 @@ BlazeComponent.extendComponent({
if (allowPrivateVisibilityOnly !== undefined && allowPrivateVisibilityOnly.booleanValue) {
query.$and.push({ 'permission': 'private' });
}
const currUser = Users.findOne(Meteor.userId());
// const currUser = Users.findOne(Meteor.userId(), {
// fields: {
// orgs: 1,
// teams: 1,
// },
// });
const currUser = ReactiveCache.getCurrentUser();
let orgIdsUserBelongs = currUser !== undefined && currUser.teams !== 'undefined' ? currUser.orgIdsUserBelongs() : '';
if (orgIdsUserBelongs && orgIdsUserBelongs != '') {

View file

@ -775,7 +775,7 @@ const filterMembers = (filterTerm) => {
members = members
.map(member => ({
member,
user: Users.findOne(member.userId)
user: ReactiveCache.getUser(member.userId)
}))
.filter(({ user }) =>
(user.profile.fullname !== undefined && user.profile.fullname.toLowerCase().indexOf(filterTerm.toLowerCase()) !== -1)
@ -1640,7 +1640,7 @@ Template.cardAssigneesPopup.helpers({
},
user() {
return Users.findOne(this.userId);
return ReactiveCache.getUser(this.userId);
},
});
@ -1655,13 +1655,13 @@ Template.cardAssigneePopup.helpers({
},
memberType() {
const user = Users.findOne(this.userId);
const user = ReactiveCache.getUser(this.userId);
return user && user.isBoardAdmin() ? 'admin' : 'normal';
},
/*
presenceStatusClassName() {
const user = Users.findOne(this.userId);
const user = ReactiveCache.getUser(this.userId);
const userPresence = presences.findOne({ userId: this.userId });
if (user && user.isInvitedTo(Session.get('currentBoard'))) return 'pending';
else if (!userPresence) return 'disconnected';
@ -1678,7 +1678,7 @@ Template.cardAssigneePopup.helpers({
},
user() {
return Users.findOne(this.userId);
return ReactiveCache.getUser(this.userId);
},
});

View file

@ -353,7 +353,7 @@ BlazeComponent.extendComponent({
const currentBoard = Utils.getCurrentBoard();
callback(
$.map(currentBoard.activeMembers(), member => {
const user = Users.findOne(member.userId);
const user = ReactiveCache.getUser(member.userId);
return user.username.indexOf(term) === 0 ? user : null;
}),
);

View file

@ -1,3 +1,5 @@
import { ReactiveCache } from '/imports/reactiveCache';
const specialHandles = [
{userId: 'board_members', username: 'board_members'},
{userId: 'card_members', username: 'card_members'}
@ -19,7 +21,7 @@ BlazeComponent.extendComponent({
currentBoard
.activeMembers()
.map(member => {
const user = Users.findOne(member.userId);
const user = ReactiveCache.getUser(member.userId);
const username = user.username;
const fullName = user.profile && user.profile !== undefined && user.profile.fullname ? user.profile.fullname : "";
return username.includes(term) || fullName.includes(term) ? user : null;
@ -334,7 +336,7 @@ Blaze.Template.registerHelper(
DOMPurify.sanitize(content, { ALLOW_UNKNOWN_PROTOCOLS: true }),
);
const knowedUsers = _.union(currentBoard.members.map(member => {
const u = Users.findOne(member.userId);
const u = ReactiveCache.getUser(member.userId);
if (u) {
member.username = u.username;
}

View file

@ -1,3 +1,5 @@
import { ReactiveCache } from '/imports/reactiveCache';
// this hides the notifications drawer if anyone clicks off of the panel
Template.body.events({
click(event) {
@ -12,7 +14,7 @@ Template.body.events({
Template.notifications.helpers({
unreadNotifications() {
const notifications = Users.findOne(Meteor.userId()).notifications();
const notifications = ReactiveCache.getCurrentUser().notifications();
const unreadNotifications = _.filter(notifications, v => !v.read);
return unreadNotifications.length;
},

View file

@ -1,3 +1,4 @@
import { ReactiveCache } from '/imports/reactiveCache';
import { toggleNotificationsDrawer } from './notifications.js';
Template.notificationsDrawer.onCreated(function() {
@ -14,7 +15,7 @@ Template.notificationsDrawer.onCreated(function() {
Template.notificationsDrawer.helpers({
transformedProfile() {
return Users.findOne(Meteor.userId());
return ReactiveCache.getCurrentUser();
},
readNotifications() {
const readNotifications = _.filter(

View file

@ -1,3 +1,4 @@
import { ReactiveCache } from '/imports/reactiveCache';
import { TAPi18n } from '/imports/i18n';
import { AttachmentStorage } from '/models/attachments';
import { CardSearchPagedComponent } from '/client/lib/cardSearch';
@ -163,7 +164,7 @@ class AdminReport extends BlazeComponent {
userNames(members) {
let text = '';
members.forEach(member => {
const user = Users.findOne(member.userId);
const user = ReactiveCache.getUser(member.userId);
text += text ? ', ' : '';
if (user) {
text += user.username;
@ -181,7 +182,7 @@ class AdminReport extends BlazeComponent {
userNames(userIds) {
let text = '';
userIds.forEach(userId => {
const user = Users.findOne(userId);
const user = ReactiveCache.getUser(userId);
text += text ? ', ' : '';
text += user.username;
});

View file

@ -1,3 +1,5 @@
import { ReactiveCache } from '/imports/reactiveCache';
const orgsPerPage = 25;
const teamsPerPage = 25;
const usersPerPage = 25;
@ -202,7 +204,7 @@ Template.teamRow.helpers({
Template.peopleRow.helpers({
userData() {
return Users.findOne(this.userId);
return ReactiveCache.getUser(this.userId);
},
});
@ -245,7 +247,7 @@ Template.editTeamPopup.helpers({
Template.editUserPopup.helpers({
user() {
return Users.findOne(this.userId);
return ReactiveCache.getUser(this.userId);
},
authentications() {
return Template.instance().authenticationMethods.get();
@ -258,12 +260,12 @@ Template.editUserPopup.helpers({
},
isSelected(match) {
const userId = Template.instance().data.userId;
const selected = Users.findOne(userId).authenticationMethod;
const selected = ReactiveCache.getUser(userId).authenticationMethod;
return selected === match;
},
isLdap() {
const userId = Template.instance().data.userId;
const selected = Users.findOne(userId).authenticationMethod;
const selected = ReactiveCache.getUser(userId).authenticationMethod;
return selected === 'ldap';
},
errorMessage() {
@ -318,7 +320,7 @@ Template.newTeamPopup.helpers({
Template.newUserPopup.helpers({
user() {
return Users.findOne(this.userId);
return ReactiveCache.getUser(this.userId);
},
authentications() {
return Template.instance().authenticationMethods.get();
@ -332,7 +334,7 @@ Template.newUserPopup.helpers({
isSelected(match) {
const userId = Template.instance().data.userId;
if(userId){
const selected = Users.findOne(userId).authenticationMethod;
const selected = ReactiveCache.getUser(userId).authenticationMethod;
return selected === match;
}
else{
@ -341,7 +343,7 @@ Template.newUserPopup.helpers({
},
isLdap() {
const userId = Template.instance().data.userId;
const selected = Users.findOne(userId).authenticationMethod;
const selected = ReactiveCache.getUser(userId).authenticationMethod;
return selected === 'ldap';
},
errorMessage() {
@ -382,7 +384,7 @@ BlazeComponent.extendComponent({
BlazeComponent.extendComponent({
onCreated() {},
user() {
return Users.findOne(this.userId);
return ReactiveCache.getUser(this.userId);
},
events() {
return [
@ -440,7 +442,7 @@ BlazeComponent.extendComponent({
if(document.getElementById('addAction').checked){
for(let i = 0; i < selectedUserChkBoxUserIds.length; i++){
currentUser = Users.findOne(selectedUserChkBoxUserIds[i]);
currentUser = ReactiveCache.getUser(selectedUserChkBoxUserIds[i]);
userTms = currentUser.teams;
if(userTms == undefined || userTms.length == 0){
userTms = [];
@ -469,7 +471,7 @@ BlazeComponent.extendComponent({
}
else{
for(let i = 0; i < selectedUserChkBoxUserIds.length; i++){
currentUser = Users.findOne(selectedUserChkBoxUserIds[i]);
currentUser = ReactiveCache.getUser(selectedUserChkBoxUserIds[i]);
userTms = currentUser.teams;
if(userTms !== undefined || userTms.length > 0)
{
@ -647,7 +649,7 @@ Template.editTeamPopup.events({
Template.editUserPopup.events({
submit(event, templateInstance) {
event.preventDefault();
const user = Users.findOne(this.userId);
const user = ReactiveCache.getUser(this.userId);
const username = templateInstance.find('.js-profile-username').value.trim();
const fullname = templateInstance.find('.js-profile-fullname').value.trim();
const initials = templateInstance.find('.js-profile-initials').value.trim();
@ -1139,19 +1141,19 @@ Template.settingsUserPopup.events({
Template.settingsUserPopup.helpers({
user() {
return Users.findOne(this.userId);
return ReactiveCache.getUser(this.userId);
},
authentications() {
return Template.instance().authenticationMethods.get();
},
isSelected(match) {
const userId = Template.instance().data.userId;
const selected = Users.findOne(userId).authenticationMethod;
const selected = ReactiveCache.getUser(userId).authenticationMethod;
return selected === match;
},
isLdap() {
const userId = Template.instance().data.userId;
const selected = Users.findOne(userId).authenticationMethod;
const selected = ReactiveCache.getUser(userId).authenticationMethod;
return selected === 'ldap';
},
errorMessage() {

View file

@ -170,13 +170,13 @@ EscapeActions.register(
Template.memberPopup.helpers({
user() {
return Users.findOne(this.userId);
return ReactiveCache.getUser(this.userId);
},
isBoardAdmin() {
return Meteor.user().isBoardAdmin();
},
memberType() {
const type = Users.findOne(this.userId).isBoardAdmin() ? 'admin' : 'normal';
const type = ReactiveCache.getUser(this.userId).isBoardAdmin() ? 'admin' : 'normal';
if (type === 'normal') {
const currentBoard = Utils.getCurrentBoard();
const commentOnly = currentBoard.hasCommentOnly(this.userId);
@ -196,7 +196,7 @@ Template.memberPopup.helpers({
}
},
isInvited() {
return Users.findOne(this.userId).isInvitedTo(Session.get('currentBoard'));
return ReactiveCache.getUser(this.userId).isInvitedTo(Session.get('currentBoard'));
},
});
@ -299,7 +299,7 @@ Template.memberPopup.events({
Template.removeMemberPopup.helpers({
user() {
return Users.findOne(this.userId);
return ReactiveCache.getUser(this.userId);
},
board() {
return Utils.getCurrentBoard();
@ -1450,7 +1450,7 @@ BlazeComponent.extendComponent({
isBoardMember() {
const userId = this.currentData().__originalId;
const user = Users.findOne(userId);
const user = ReactiveCache.getUser(userId);
return user && user.isBoardMember();
},

View file

@ -16,13 +16,13 @@ Template.userAvatar.helpers({
},
memberType() {
const user = Users.findOne(this.userId);
const user = ReactiveCache.getUser(this.userId);
return user && user.isBoardAdmin() ? 'admin' : 'normal';
},
/*
presenceStatusClassName() {
const user = Users.findOne(this.userId);
const user = ReactiveCache.getUser(this.userId);
const userPresence = presences.findOne({ userId: this.userId });
if (user && user.isInvitedTo(Session.get('currentBoard'))) return 'pending';
else if (!userPresence) return 'disconnected';
@ -36,12 +36,12 @@ Template.userAvatar.helpers({
Template.userAvatarInitials.helpers({
initials() {
const user = Users.findOne(this.userId);
const user = ReactiveCache.getUser(this.userId);
return user && user.getInitials();
},
viewPortWidth() {
const user = Users.findOne(this.userId);
const user = ReactiveCache.getUser(this.userId);
return ((user && user.getInitials().length) || 1) * 12;
},
});
@ -249,7 +249,7 @@ Template.cardMembersPopup.helpers({
},
user() {
return Users.findOne(this.userId);
return ReactiveCache.getUser(this.userId);
},
});
@ -264,7 +264,7 @@ Template.cardMembersPopup.events({
Template.cardMemberPopup.helpers({
user() {
return Users.findOne(this.userId);
return ReactiveCache.getUser(this.userId);
},
});

View file

@ -1,3 +1,4 @@
import { ReactiveCache } from '/imports/reactiveCache';
import { Blaze } from 'meteor/blaze';
import { Session } from 'meteor/session';
import moment from 'moment/min/moment-with-locales';
@ -22,7 +23,7 @@ Blaze.registerHelper('currentSetting', () => {
return ret;
});
Blaze.registerHelper('getUser', userId => Users.findOne(userId));
Blaze.registerHelper('getUser', userId => ReactiveCache.getUser(userId));
Blaze.registerHelper('concat', (...args) => args.slice(0, -1).join(''));