Move every Users.findOne(idOrFirstObjectSelector, options) to the ReactiveCache

This commit is contained in:
Martin Filser 2023-02-04 11:16:53 +01:00
parent 68610e5066
commit 0767f50af8
17 changed files with 43 additions and 33 deletions

View file

@ -1,3 +1,4 @@
import { ReactiveCache } from '/imports/reactiveCache';
import { Exporter } from './exporter';
import { Meteor } from 'meteor/meteor';
@ -43,7 +44,7 @@ if (Meteor.isServer) {
});
} else if (!Meteor.settings.public.sandstorm) {
Authentication.checkUserId(req.userId);
user = Users.findOne({ _id: req.userId, isAdmin: true });
user = ReactiveCache.getUser({ _id: req.userId, isAdmin: true });
}
const exporter = new Exporter(boardId);
if (exporter.canExport(user) || impersonateDone) {
@ -107,7 +108,7 @@ if (Meteor.isServer) {
});
} else if (!Meteor.settings.public.sandstorm) {
Authentication.checkUserId(req.userId);
user = Users.findOne({ _id: req.userId, isAdmin: true });
user = ReactiveCache.getUser({ _id: req.userId, isAdmin: true });
}
const exporter = new Exporter(boardId, attachmentId);
if (exporter.canExport(user) || impersonateDone) {
@ -163,7 +164,7 @@ if (Meteor.isServer) {
});
} else if (!Meteor.settings.public.sandstorm) {
Authentication.checkUserId(req.userId);
user = Users.findOne({
user = ReactiveCache.getUser({
_id: req.userId,
isAdmin: true,
});

View file

@ -1,3 +1,4 @@
import { ReactiveCache } from '/imports/reactiveCache';
import { TAPi18n } from '/imports/i18n';
import { runOnServer } from './runOnServer';
@ -46,7 +47,7 @@ runOnServer(function() {
});
} else if (!Meteor.settings.public.sandstorm) {
Authentication.checkUserId(req.userId);
user = Users.findOne({
user = ReactiveCache.getUser({
_id: req.userId,
isAdmin: true,
});

View file

@ -1,3 +1,4 @@
import { ReactiveCache } from '/imports/reactiveCache';
import { TAPi18n } from '/imports/i18n';
import { runOnServer } from './runOnServer';
@ -48,7 +49,7 @@ runOnServer(function() {
});
} else if (!Meteor.settings.public.sandstorm) {
Authentication.checkUserId(req.userId);
user = Users.findOne({
user = ReactiveCache.getUser({
_id: req.userId,
isAdmin: true,
});

View file

@ -349,7 +349,7 @@ if (Meteor.isServer) {
emails.forEach(email => {
if (email && SimpleSchema.RegEx.Email.test(email)) {
// Checks if the email is already link to an account.
const userExist = Users.findOne({ email });
const userExist = ReactiveCache.getUser({ email });
if (userExist) {
rc = -1;
throw new Meteor.Error(

View file

@ -515,7 +515,7 @@ Users.allow({
const adminsNumber = Users.find({
isAdmin: true,
}).count();
const { isAdmin } = Users.findOne(
const isAdmin = ReactiveCache.getUser(
{
_id: userId,
},
@ -1262,10 +1262,8 @@ if (Meteor.isServer) {
from: 'admin',
});
const user =
Users.findOne(username) ||
Users.findOne({
username,
});
ReactiveCache.getUser(username) ||
ReactiveCache.getUser({ username });
if (user) {
Users.update(user._id, {
$set: {
@ -1305,7 +1303,7 @@ if (Meteor.isServer) {
if (Array.isArray(email)) {
email = email.shift();
}
const existingUser = Users.findOne(
const existingUser = ReactiveCache.getUser(
{
'emails.address': email,
},
@ -1402,7 +1400,7 @@ if (Meteor.isServer) {
const posAt = username.indexOf('@');
let user = null;
if (posAt >= 0) {
user = Users.findOne({
user = ReactiveCache.getUser({
emails: {
$elemMatch: {
address: username,
@ -1411,10 +1409,8 @@ if (Meteor.isServer) {
});
} else {
user =
Users.findOne(username) ||
Users.findOne({
username,
});
ReactiveCache.getUser(username) ||
ReactiveCache.getUser({ username });
}
if (user) {
if (user._id === inviter._id)

View file

@ -213,7 +213,7 @@ export class WekanCreator {
importedMember.fullName = user.profile.fullname;
}
importedMember.username = user.username;
const wekanUser = Users.findOne({ username: importedMember.username });
const wekanUser = ReactiveCache.getUser({ username: importedMember.username });
if (wekanUser) {
importedMember.wekanId = wekanUser._id;
}

View file

@ -1,3 +1,5 @@
import { ReactiveCache } from '/imports/reactiveCache';
export function getMembersToMap(data) {
// we will work on the list itself (an ordered array of objects) when a
// mapping is done, we add a 'wekan' field to the object representing the
@ -15,7 +17,7 @@ export function getMembersToMap(data) {
importedMember.fullName = user.profile.fullname;
}
importedMember.username = user.username;
const wekanUser = Users.findOne({ username: importedMember.username });
const wekanUser = ReactiveCache.getUser({ username: importedMember.username });
if (wekanUser) {
importedMember.wekanId = wekanUser._id;
}