mirror of
https://github.com/wekan/wekan.git
synced 2025-09-22 01:50:48 +02:00
Move every Users.find(idOrFirstObjectSelector, options) to the ReactiveCache (directory models/)
This commit is contained in:
parent
81c9bb6899
commit
030359aa0e
7 changed files with 38 additions and 41 deletions
|
@ -883,7 +883,7 @@ Boards.helpers({
|
|||
},
|
||||
|
||||
memberUsers() {
|
||||
return Users.find({ _id: { $in: _.pluck(this.members, 'userId') } });
|
||||
return ReactiveCache.getUsers({ _id: { $in: _.pluck(this.members, 'userId') } });
|
||||
},
|
||||
|
||||
getLabel(name, color) {
|
||||
|
|
|
@ -1483,13 +1483,13 @@ Cards.helpers({
|
|||
},
|
||||
voteMemberPositive() {
|
||||
if (this.vote && this.vote.positive)
|
||||
return Users.find({ _id: { $in: this.vote.positive } });
|
||||
return ReactiveCache.getUsers({ _id: { $in: this.vote.positive } });
|
||||
return [];
|
||||
},
|
||||
|
||||
voteMemberNegative() {
|
||||
if (this.vote && this.vote.negative)
|
||||
return Users.find({ _id: { $in: this.vote.negative } });
|
||||
return ReactiveCache.getUsers({ _id: { $in: this.vote.negative } });
|
||||
return [];
|
||||
},
|
||||
voteState() {
|
||||
|
@ -1577,52 +1577,52 @@ Cards.helpers({
|
|||
},
|
||||
pokerMemberOne() {
|
||||
if (this.poker && this.poker.one)
|
||||
return Users.find({ _id: { $in: this.poker.one } });
|
||||
return ReactiveCache.getUsers({ _id: { $in: this.poker.one } });
|
||||
return [];
|
||||
},
|
||||
pokerMemberTwo() {
|
||||
if (this.poker && this.poker.two)
|
||||
return Users.find({ _id: { $in: this.poker.two } });
|
||||
return ReactiveCache.getUsers({ _id: { $in: this.poker.two } });
|
||||
return [];
|
||||
},
|
||||
pokerMemberThree() {
|
||||
if (this.poker && this.poker.three)
|
||||
return Users.find({ _id: { $in: this.poker.three } });
|
||||
return ReactiveCache.getUsers({ _id: { $in: this.poker.three } });
|
||||
return [];
|
||||
},
|
||||
pokerMemberFive() {
|
||||
if (this.poker && this.poker.five)
|
||||
return Users.find({ _id: { $in: this.poker.five } });
|
||||
return ReactiveCache.getUsers({ _id: { $in: this.poker.five } });
|
||||
return [];
|
||||
},
|
||||
pokerMemberEight() {
|
||||
if (this.poker && this.poker.eight)
|
||||
return Users.find({ _id: { $in: this.poker.eight } });
|
||||
return ReactiveCache.getUsers({ _id: { $in: this.poker.eight } });
|
||||
return [];
|
||||
},
|
||||
pokerMemberThirteen() {
|
||||
if (this.poker && this.poker.thirteen)
|
||||
return Users.find({ _id: { $in: this.poker.thirteen } });
|
||||
return ReactiveCache.getUsers({ _id: { $in: this.poker.thirteen } });
|
||||
return [];
|
||||
},
|
||||
pokerMemberTwenty() {
|
||||
if (this.poker && this.poker.twenty)
|
||||
return Users.find({ _id: { $in: this.poker.twenty } });
|
||||
return ReactiveCache.getUsers({ _id: { $in: this.poker.twenty } });
|
||||
return [];
|
||||
},
|
||||
pokerMemberForty() {
|
||||
if (this.poker && this.poker.forty)
|
||||
return Users.find({ _id: { $in: this.poker.forty } });
|
||||
return ReactiveCache.getUsers({ _id: { $in: this.poker.forty } });
|
||||
return [];
|
||||
},
|
||||
pokerMemberOneHundred() {
|
||||
if (this.poker && this.poker.oneHundred)
|
||||
return Users.find({ _id: { $in: this.poker.oneHundred } });
|
||||
return ReactiveCache.getUsers({ _id: { $in: this.poker.oneHundred } });
|
||||
return [];
|
||||
},
|
||||
pokerMemberUnsure() {
|
||||
if (this.poker && this.poker.unsure)
|
||||
return Users.find({ _id: { $in: this.poker.unsure } });
|
||||
return ReactiveCache.getUsers({ _id: { $in: this.poker.unsure } });
|
||||
return [];
|
||||
},
|
||||
pokerState() {
|
||||
|
|
|
@ -192,8 +192,7 @@ export class Exporter {
|
|||
'profile.avatarUrl': 1,
|
||||
},
|
||||
};
|
||||
result.users = Users.find(byUserIds, userFields)
|
||||
.fetch()
|
||||
result.users = ReactiveCache.getUsers(byUserIds, userFields)
|
||||
.map((user) => {
|
||||
// user avatar is stored as a relative url, we export absolute
|
||||
if ((user.profile || {}).avatarUrl) {
|
||||
|
|
|
@ -147,8 +147,7 @@ class ExporterCardPDF {
|
|||
'profile.avatarUrl': 1,
|
||||
},
|
||||
};
|
||||
result.users = Users.find(byUserIds, userFields)
|
||||
.fetch()
|
||||
result.users = ReactiveCache.getUsers(byUserIds, userFields)
|
||||
.map((user) => {
|
||||
// user avatar is stored as a relative url, we export absolute
|
||||
if ((user.profile || {}).avatarUrl) {
|
||||
|
|
|
@ -149,8 +149,7 @@ class ExporterExcel {
|
|||
'profile.avatarUrl': 1,
|
||||
},
|
||||
};
|
||||
result.users = Users.find(byUserIds, userFields)
|
||||
.fetch()
|
||||
result.users = ReactiveCache.getUsers(byUserIds, userFields)
|
||||
.map((user) => {
|
||||
// user avatar is stored as a relative url, we export absolute
|
||||
if ((user.profile || {}).avatarUrl) {
|
||||
|
|
|
@ -69,7 +69,7 @@ Meteor.startup(() => {
|
|||
metricsRes += '# Number of registered users\n';
|
||||
|
||||
// Get number of registered user
|
||||
resCount = Users.find({}).count(); // KPI 2
|
||||
resCount = ReactiveCache.getUsers({}).length; // KPI 2
|
||||
metricsRes += 'wekan_registeredUsers ' + resCount + '\n';
|
||||
resCount = 0;
|
||||
|
||||
|
@ -87,7 +87,7 @@ Meteor.startup(() => {
|
|||
// Get number of registered boards by registered users
|
||||
resCount =
|
||||
Boards.find({ archived: false, type: 'board' }).count() /
|
||||
Users.find({}).count(); // KPI 4
|
||||
ReactiveCache.getUsers({}).length; // KPI 4
|
||||
metricsRes +=
|
||||
'wekan_registeredboardsBysRegisteredUsers ' + resCount + '\n';
|
||||
resCount = 0;
|
||||
|
@ -118,9 +118,9 @@ Meteor.startup(() => {
|
|||
let dateWithXdaysAgo = new Date(
|
||||
new Date() - xdays * 24 * 60 * 60 * 1000,
|
||||
);
|
||||
resCount = Users.find({
|
||||
resCount = ReactiveCache.getUsers({
|
||||
lastConnectionDate: { $gte: dateWithXdaysAgo },
|
||||
}).count(); // KPI 5
|
||||
}).length; // KPI 5
|
||||
metricsRes +=
|
||||
'wekan_usersWithLastConnectionDated5DaysAgo ' + resCount + '\n';
|
||||
resCount = 0;
|
||||
|
@ -131,9 +131,9 @@ Meteor.startup(() => {
|
|||
// Get number of users with last connection dated 10 days ago
|
||||
xdays = 10;
|
||||
dateWithXdaysAgo = new Date(new Date() - xdays * 24 * 60 * 60 * 1000);
|
||||
resCount = Users.find({
|
||||
resCount = ReactiveCache.getUsers({
|
||||
lastConnectionDate: { $gte: dateWithXdaysAgo },
|
||||
}).count(); // KPI 5
|
||||
}).length; // KPI 5
|
||||
metricsRes +=
|
||||
'wekan_usersWithLastConnectionDated10DaysAgo ' + resCount + '\n';
|
||||
resCount = 0;
|
||||
|
@ -144,9 +144,9 @@ Meteor.startup(() => {
|
|||
// Get number of users with last connection dated 20 days ago
|
||||
xdays = 20;
|
||||
dateWithXdaysAgo = new Date(new Date() - xdays * 24 * 60 * 60 * 1000);
|
||||
resCount = Users.find({
|
||||
resCount = ReactiveCache.getUsers({
|
||||
lastConnectionDate: { $gte: dateWithXdaysAgo },
|
||||
}).count(); // KPI 5
|
||||
}).length; // KPI 5
|
||||
metricsRes +=
|
||||
'wekan_usersWithLastConnectionDated20DaysAgo ' + resCount + '\n';
|
||||
resCount = 0;
|
||||
|
@ -157,9 +157,9 @@ Meteor.startup(() => {
|
|||
// Get number of users with last connection dated 20 days ago
|
||||
xdays = 30;
|
||||
dateWithXdaysAgo = new Date(new Date() - xdays * 24 * 60 * 60 * 1000);
|
||||
resCount = Users.find({
|
||||
resCount = ReactiveCache.getUsers({
|
||||
lastConnectionDate: { $gte: dateWithXdaysAgo },
|
||||
}).count(); // KPI 5
|
||||
}).length; // KPI 5
|
||||
metricsRes +=
|
||||
'wekan_usersWithLastConnectionDated30DaysAgo ' + resCount + '\n';
|
||||
resCount = 0;
|
||||
|
|
|
@ -512,9 +512,9 @@ Users.allow({
|
|||
return doc._id === userId;
|
||||
},
|
||||
remove(userId, doc) {
|
||||
const adminsNumber = Users.find({
|
||||
const adminsNumber = ReactiveCache.getUsers({
|
||||
isAdmin: true,
|
||||
}).count();
|
||||
}).length;
|
||||
const isAdmin = ReactiveCache.getUser(
|
||||
{
|
||||
_id: userId,
|
||||
|
@ -1242,12 +1242,12 @@ if (Meteor.isServer) {
|
|||
check(userOrgsArray, Array);
|
||||
check(userTeamsArray, Array);
|
||||
if (ReactiveCache.getCurrentUser()?.isAdmin) {
|
||||
const nUsersWithUsername = Users.find({
|
||||
const nUsersWithUsername = ReactiveCache.getUsers({
|
||||
username,
|
||||
}).count();
|
||||
const nUsersWithEmail = Users.find({
|
||||
}).length;
|
||||
const nUsersWithEmail = ReactiveCache.getUsers({
|
||||
email,
|
||||
}).count();
|
||||
}).length;
|
||||
if (nUsersWithUsername > 0) {
|
||||
throw new Meteor.Error('username-already-taken');
|
||||
} else if (nUsersWithEmail > 0) {
|
||||
|
@ -1282,9 +1282,9 @@ if (Meteor.isServer) {
|
|||
check(username, String);
|
||||
check(userId, String);
|
||||
if (ReactiveCache.getCurrentUser()?.isAdmin) {
|
||||
const nUsersWithUsername = Users.find({
|
||||
const nUsersWithUsername = ReactiveCache.getUsers({
|
||||
username,
|
||||
}).count();
|
||||
}).length;
|
||||
if (nUsersWithUsername > 0) {
|
||||
throw new Meteor.Error('username-already-taken');
|
||||
} else {
|
||||
|
@ -1539,7 +1539,7 @@ if (Meteor.isServer) {
|
|||
check(teamId, String);
|
||||
check(teamDisplayName, String);
|
||||
if (ReactiveCache.getCurrentUser()?.isAdmin) {
|
||||
Users.find({
|
||||
ReactiveCache.getUsers({
|
||||
teams: {
|
||||
$elemMatch: { teamId: teamId },
|
||||
},
|
||||
|
@ -1564,7 +1564,7 @@ if (Meteor.isServer) {
|
|||
check(orgId, String);
|
||||
check(orgDisplayName, String);
|
||||
if (ReactiveCache.getCurrentUser()?.isAdmin) {
|
||||
Users.find({
|
||||
ReactiveCache.getUsers({
|
||||
orgs: {
|
||||
$elemMatch: { orgId: orgId },
|
||||
},
|
||||
|
@ -1587,7 +1587,7 @@ if (Meteor.isServer) {
|
|||
},
|
||||
});
|
||||
Accounts.onCreateUser((options, user) => {
|
||||
const userCount = Users.find().count();
|
||||
const userCount = ReactiveCache.getUsers().length;
|
||||
if (userCount === 0) {
|
||||
user.isAdmin = true;
|
||||
}
|
||||
|
@ -1715,7 +1715,7 @@ const addCronJob = _.debounce(
|
|||
name: 'notification_cleanup',
|
||||
schedule: (parser) => parser.text('every 1 days'),
|
||||
job: () => {
|
||||
for (const user of Users.find()) {
|
||||
for (const user of ReactiveCache.getUsers()) {
|
||||
if (!user.profile || !user.profile.notifications) continue;
|
||||
for (const notification of user.profile.notifications) {
|
||||
if (notification.read) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue