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

This commit is contained in:
Martin Filser 2023-02-04 17:25:09 +01:00
parent 6c3170360b
commit 92052458f5
4 changed files with 14 additions and 20 deletions

View file

@ -35,7 +35,7 @@ if (Meteor.isServer) {
const loginToken = req.query.authToken; const loginToken = req.query.authToken;
if (loginToken) { if (loginToken) {
const hashToken = Accounts._hashLoginToken(loginToken); const hashToken = Accounts._hashLoginToken(loginToken);
user = Meteor.users.findOne({ user = ReactiveCache.getUser({
'services.resume.loginTokens.hashedToken': hashToken, 'services.resume.loginTokens.hashedToken': hashToken,
}); });
adminId = user._id.toString(); adminId = user._id.toString();
@ -99,7 +99,7 @@ if (Meteor.isServer) {
const loginToken = req.query.authToken; const loginToken = req.query.authToken;
if (loginToken) { if (loginToken) {
const hashToken = Accounts._hashLoginToken(loginToken); const hashToken = Accounts._hashLoginToken(loginToken);
user = Meteor.users.findOne({ user = ReactiveCache.getUser({
'services.resume.loginTokens.hashedToken': hashToken, 'services.resume.loginTokens.hashedToken': hashToken,
}); });
adminId = user._id.toString(); adminId = user._id.toString();
@ -155,7 +155,7 @@ if (Meteor.isServer) {
const loginToken = params.query.authToken; const loginToken = params.query.authToken;
if (loginToken) { if (loginToken) {
const hashToken = Accounts._hashLoginToken(loginToken); const hashToken = Accounts._hashLoginToken(loginToken);
user = Meteor.users.findOne({ user = ReactiveCache.getUser({
'services.resume.loginTokens.hashedToken': hashToken, 'services.resume.loginTokens.hashedToken': hashToken,
}); });
adminId = user._id.toString(); adminId = user._id.toString();

View file

@ -38,7 +38,7 @@ runOnServer(function() {
const loginToken = params.query.authToken; const loginToken = params.query.authToken;
if (loginToken) { if (loginToken) {
const hashToken = Accounts._hashLoginToken(loginToken); const hashToken = Accounts._hashLoginToken(loginToken);
user = Meteor.users.findOne({ user = ReactiveCache.getUser({
'services.resume.loginTokens.hashedToken': hashToken, 'services.resume.loginTokens.hashedToken': hashToken,
}); });
adminId = user._id.toString(); adminId = user._id.toString();

View file

@ -40,7 +40,7 @@ runOnServer(function() {
const loginToken = params.query.authToken; const loginToken = params.query.authToken;
if (loginToken) { if (loginToken) {
const hashToken = Accounts._hashLoginToken(loginToken); const hashToken = Accounts._hashLoginToken(loginToken);
user = Meteor.users.findOne({ user = ReactiveCache.getUser({
'services.resume.loginTokens.hashedToken': hashToken, 'services.resume.loginTokens.hashedToken': hashToken,
}); });
adminId = user._id.toString(); adminId = user._id.toString();

View file

@ -1518,7 +1518,7 @@ if (Meteor.isServer) {
impersonate(userId) { impersonate(userId) {
check(userId, String); check(userId, String);
if (!Meteor.users.findOne(userId)) if (!ReactiveCache.getUser(userId))
throw new Meteor.Error(404, 'User not found'); throw new Meteor.Error(404, 'User not found');
if (!ReactiveCache.getCurrentUser().isAdmin) if (!ReactiveCache.getCurrentUser().isAdmin)
throw new Meteor.Error(403, 'Permission denied'); throw new Meteor.Error(403, 'Permission denied');
@ -1621,7 +1621,7 @@ if (Meteor.isServer) {
user.authenticationMethod = 'oauth2'; user.authenticationMethod = 'oauth2';
// see if any existing user has this email address or username, otherwise create new // see if any existing user has this email address or username, otherwise create new
const existingUser = Meteor.users.findOne({ const existingUser = ReactiveCache.getUser({
$or: [ $or: [
{ {
'emails.address': email, 'emails.address': email,
@ -2025,7 +2025,7 @@ if (Meteor.isServer) {
JsonRoutes.add('GET', '/api/user', function (req, res) { JsonRoutes.add('GET', '/api/user', function (req, res) {
try { try {
Authentication.checkLoggedIn(req.userId); Authentication.checkLoggedIn(req.userId);
const data = Meteor.users.findOne({ const data = ReactiveCache.getUser({
_id: req.userId, _id: req.userId,
}); });
delete data.services; delete data.services;
@ -2106,11 +2106,11 @@ if (Meteor.isServer) {
try { try {
Authentication.checkUserId(req.userId); Authentication.checkUserId(req.userId);
let id = req.params.userId; let id = req.params.userId;
let user = Meteor.users.findOne({ let user = ReactiveCache.getUser({
_id: id, _id: id,
}); });
if (!user) { if (!user) {
user = Meteor.users.findOne({ user = ReactiveCache.getUser({
username: id, username: id,
}); });
id = user._id; id = user._id;
@ -2171,7 +2171,7 @@ if (Meteor.isServer) {
Authentication.checkUserId(req.userId); Authentication.checkUserId(req.userId);
const id = req.params.userId; const id = req.params.userId;
const action = req.body.action; const action = req.body.action;
let data = Meteor.users.findOne({ let data = ReactiveCache.getUser({
_id: id, _id: id,
}); });
if (data !== undefined) { if (data !== undefined) {
@ -2221,9 +2221,7 @@ if (Meteor.isServer) {
}, },
); );
} }
data = Meteor.users.findOne({ data = ReactiveCache.getUser(id);
_id: id,
});
} }
} }
JsonRoutes.sendResult(res, { JsonRoutes.sendResult(res, {
@ -2269,9 +2267,7 @@ if (Meteor.isServer) {
const boardId = req.params.boardId; const boardId = req.params.boardId;
const action = req.body.action; const action = req.body.action;
const { isAdmin, isNoComments, isCommentOnly, isWorker } = req.body; const { isAdmin, isNoComments, isCommentOnly, isWorker } = req.body;
let data = Meteor.users.findOne({ let data = ReactiveCache.getUser(userId);
_id: userId,
});
if (data !== undefined) { if (data !== undefined) {
if (action === 'add') { if (action === 'add') {
data = Boards.find({ data = Boards.find({
@ -2332,9 +2328,7 @@ if (Meteor.isServer) {
const userId = req.params.userId; const userId = req.params.userId;
const boardId = req.params.boardId; const boardId = req.params.boardId;
const action = req.body.action; const action = req.body.action;
let data = Meteor.users.findOne({ let data = ReactiveCache.getUser(userId);
_id: userId,
});
if (data !== undefined) { if (data !== undefined) {
if (action === 'remove') { if (action === 'remove') {
data = Boards.find({ data = Boards.find({