Ver Fonte

Move every Users.find(idOrFirstObjectSelector, options) to the ReactiveCache (directory models/)

Martin Filser há 2 anos atrás
pai
commit
030359aa0e

+ 1 - 1
models/boards.js

@@ -883,7 +883,7 @@ Boards.helpers({
   },
   },
 
 
   memberUsers() {
   memberUsers() {
-    return Users.find({ _id: { $in: _.pluck(this.members, 'userId') } });
+    return ReactiveCache.getUsers({ _id: { $in: _.pluck(this.members, 'userId') } });
   },
   },
 
 
   getLabel(name, color) {
   getLabel(name, color) {

+ 12 - 12
models/cards.js

@@ -1483,13 +1483,13 @@ Cards.helpers({
   },
   },
   voteMemberPositive() {
   voteMemberPositive() {
     if (this.vote && this.vote.positive)
     if (this.vote && this.vote.positive)
-      return Users.find({ _id: { $in: this.vote.positive } });
+      return ReactiveCache.getUsers({ _id: { $in: this.vote.positive } });
     return [];
     return [];
   },
   },
 
 
   voteMemberNegative() {
   voteMemberNegative() {
     if (this.vote && this.vote.negative)
     if (this.vote && this.vote.negative)
-      return Users.find({ _id: { $in: this.vote.negative } });
+      return ReactiveCache.getUsers({ _id: { $in: this.vote.negative } });
     return [];
     return [];
   },
   },
   voteState() {
   voteState() {
@@ -1577,52 +1577,52 @@ Cards.helpers({
   },
   },
   pokerMemberOne() {
   pokerMemberOne() {
     if (this.poker && this.poker.one)
     if (this.poker && this.poker.one)
-      return Users.find({ _id: { $in: this.poker.one } });
+      return ReactiveCache.getUsers({ _id: { $in: this.poker.one } });
     return [];
     return [];
   },
   },
   pokerMemberTwo() {
   pokerMemberTwo() {
     if (this.poker && this.poker.two)
     if (this.poker && this.poker.two)
-      return Users.find({ _id: { $in: this.poker.two } });
+      return ReactiveCache.getUsers({ _id: { $in: this.poker.two } });
     return [];
     return [];
   },
   },
   pokerMemberThree() {
   pokerMemberThree() {
     if (this.poker && this.poker.three)
     if (this.poker && this.poker.three)
-      return Users.find({ _id: { $in: this.poker.three } });
+      return ReactiveCache.getUsers({ _id: { $in: this.poker.three } });
     return [];
     return [];
   },
   },
   pokerMemberFive() {
   pokerMemberFive() {
     if (this.poker && this.poker.five)
     if (this.poker && this.poker.five)
-      return Users.find({ _id: { $in: this.poker.five } });
+      return ReactiveCache.getUsers({ _id: { $in: this.poker.five } });
     return [];
     return [];
   },
   },
   pokerMemberEight() {
   pokerMemberEight() {
     if (this.poker && this.poker.eight)
     if (this.poker && this.poker.eight)
-      return Users.find({ _id: { $in: this.poker.eight } });
+      return ReactiveCache.getUsers({ _id: { $in: this.poker.eight } });
     return [];
     return [];
   },
   },
   pokerMemberThirteen() {
   pokerMemberThirteen() {
     if (this.poker && this.poker.thirteen)
     if (this.poker && this.poker.thirteen)
-      return Users.find({ _id: { $in: this.poker.thirteen } });
+      return ReactiveCache.getUsers({ _id: { $in: this.poker.thirteen } });
     return [];
     return [];
   },
   },
   pokerMemberTwenty() {
   pokerMemberTwenty() {
     if (this.poker && this.poker.twenty)
     if (this.poker && this.poker.twenty)
-      return Users.find({ _id: { $in: this.poker.twenty } });
+      return ReactiveCache.getUsers({ _id: { $in: this.poker.twenty } });
     return [];
     return [];
   },
   },
   pokerMemberForty() {
   pokerMemberForty() {
     if (this.poker && this.poker.forty)
     if (this.poker && this.poker.forty)
-      return Users.find({ _id: { $in: this.poker.forty } });
+      return ReactiveCache.getUsers({ _id: { $in: this.poker.forty } });
     return [];
     return [];
   },
   },
   pokerMemberOneHundred() {
   pokerMemberOneHundred() {
     if (this.poker && this.poker.oneHundred)
     if (this.poker && this.poker.oneHundred)
-      return Users.find({ _id: { $in: this.poker.oneHundred } });
+      return ReactiveCache.getUsers({ _id: { $in: this.poker.oneHundred } });
     return [];
     return [];
   },
   },
   pokerMemberUnsure() {
   pokerMemberUnsure() {
     if (this.poker && this.poker.unsure)
     if (this.poker && this.poker.unsure)
-      return Users.find({ _id: { $in: this.poker.unsure } });
+      return ReactiveCache.getUsers({ _id: { $in: this.poker.unsure } });
     return [];
     return [];
   },
   },
   pokerState() {
   pokerState() {

+ 1 - 2
models/exporter.js

@@ -192,8 +192,7 @@ export class Exporter {
         'profile.avatarUrl': 1,
         'profile.avatarUrl': 1,
       },
       },
     };
     };
-    result.users = Users.find(byUserIds, userFields)
-      .fetch()
+    result.users = ReactiveCache.getUsers(byUserIds, userFields)
       .map((user) => {
       .map((user) => {
         // user avatar is stored as a relative url, we export absolute
         // user avatar is stored as a relative url, we export absolute
         if ((user.profile || {}).avatarUrl) {
         if ((user.profile || {}).avatarUrl) {

+ 1 - 2
models/server/ExporterCardPDF.js

@@ -147,8 +147,7 @@ class ExporterCardPDF {
             'profile.avatarUrl': 1,
             'profile.avatarUrl': 1,
           },
           },
         };
         };
-        result.users = Users.find(byUserIds, userFields)
-          .fetch()
+        result.users = ReactiveCache.getUsers(byUserIds, userFields)
           .map((user) => {
           .map((user) => {
             // user avatar is stored as a relative url, we export absolute
             // user avatar is stored as a relative url, we export absolute
             if ((user.profile || {}).avatarUrl) {
             if ((user.profile || {}).avatarUrl) {

+ 1 - 2
models/server/ExporterExcel.js

@@ -149,8 +149,7 @@ class ExporterExcel {
         'profile.avatarUrl': 1,
         'profile.avatarUrl': 1,
       },
       },
     };
     };
-    result.users = Users.find(byUserIds, userFields)
-      .fetch()
+    result.users = ReactiveCache.getUsers(byUserIds, userFields)
       .map((user) => {
       .map((user) => {
         // user avatar is stored as a relative url, we export absolute
         // user avatar is stored as a relative url, we export absolute
         if ((user.profile || {}).avatarUrl) {
         if ((user.profile || {}).avatarUrl) {

+ 10 - 10
models/server/metrics.js

@@ -69,7 +69,7 @@ Meteor.startup(() => {
         metricsRes += '# Number of registered users\n';
         metricsRes += '# Number of registered users\n';
 
 
         // Get number of registered user
         // Get number of registered user
-        resCount = Users.find({}).count(); // KPI 2
+        resCount = ReactiveCache.getUsers({}).length; // KPI 2
         metricsRes += 'wekan_registeredUsers ' + resCount + '\n';
         metricsRes += 'wekan_registeredUsers ' + resCount + '\n';
         resCount = 0;
         resCount = 0;
 
 
@@ -87,7 +87,7 @@ Meteor.startup(() => {
         // Get number of registered boards by registered users
         // Get number of registered boards by registered users
         resCount =
         resCount =
           Boards.find({ archived: false, type: 'board' }).count() /
           Boards.find({ archived: false, type: 'board' }).count() /
-          Users.find({}).count(); // KPI 4
+          ReactiveCache.getUsers({}).length; // KPI 4
         metricsRes +=
         metricsRes +=
           'wekan_registeredboardsBysRegisteredUsers ' + resCount + '\n';
           'wekan_registeredboardsBysRegisteredUsers ' + resCount + '\n';
         resCount = 0;
         resCount = 0;
@@ -118,9 +118,9 @@ Meteor.startup(() => {
         let dateWithXdaysAgo = new Date(
         let dateWithXdaysAgo = new Date(
           new Date() - xdays * 24 * 60 * 60 * 1000,
           new Date() - xdays * 24 * 60 * 60 * 1000,
         );
         );
-        resCount = Users.find({
+        resCount = ReactiveCache.getUsers({
           lastConnectionDate: { $gte: dateWithXdaysAgo },
           lastConnectionDate: { $gte: dateWithXdaysAgo },
-        }).count(); // KPI 5
+        }).length; // KPI 5
         metricsRes +=
         metricsRes +=
           'wekan_usersWithLastConnectionDated5DaysAgo ' + resCount + '\n';
           'wekan_usersWithLastConnectionDated5DaysAgo ' + resCount + '\n';
         resCount = 0;
         resCount = 0;
@@ -131,9 +131,9 @@ Meteor.startup(() => {
         // Get number of users with last connection dated 10 days ago
         // Get number of users with last connection dated 10 days ago
         xdays = 10;
         xdays = 10;
         dateWithXdaysAgo = new Date(new Date() - xdays * 24 * 60 * 60 * 1000);
         dateWithXdaysAgo = new Date(new Date() - xdays * 24 * 60 * 60 * 1000);
-        resCount = Users.find({
+        resCount = ReactiveCache.getUsers({
           lastConnectionDate: { $gte: dateWithXdaysAgo },
           lastConnectionDate: { $gte: dateWithXdaysAgo },
-        }).count(); // KPI 5
+        }).length; // KPI 5
         metricsRes +=
         metricsRes +=
           'wekan_usersWithLastConnectionDated10DaysAgo ' + resCount + '\n';
           'wekan_usersWithLastConnectionDated10DaysAgo ' + resCount + '\n';
         resCount = 0;
         resCount = 0;
@@ -144,9 +144,9 @@ Meteor.startup(() => {
         // Get number of users with last connection dated 20 days ago
         // Get number of users with last connection dated 20 days ago
         xdays = 20;
         xdays = 20;
         dateWithXdaysAgo = new Date(new Date() - xdays * 24 * 60 * 60 * 1000);
         dateWithXdaysAgo = new Date(new Date() - xdays * 24 * 60 * 60 * 1000);
-        resCount = Users.find({
+        resCount = ReactiveCache.getUsers({
           lastConnectionDate: { $gte: dateWithXdaysAgo },
           lastConnectionDate: { $gte: dateWithXdaysAgo },
-        }).count(); // KPI 5
+        }).length; // KPI 5
         metricsRes +=
         metricsRes +=
           'wekan_usersWithLastConnectionDated20DaysAgo ' + resCount + '\n';
           'wekan_usersWithLastConnectionDated20DaysAgo ' + resCount + '\n';
         resCount = 0;
         resCount = 0;
@@ -157,9 +157,9 @@ Meteor.startup(() => {
         // Get number of users with last connection dated 20 days ago
         // Get number of users with last connection dated 20 days ago
         xdays = 30;
         xdays = 30;
         dateWithXdaysAgo = new Date(new Date() - xdays * 24 * 60 * 60 * 1000);
         dateWithXdaysAgo = new Date(new Date() - xdays * 24 * 60 * 60 * 1000);
-        resCount = Users.find({
+        resCount = ReactiveCache.getUsers({
           lastConnectionDate: { $gte: dateWithXdaysAgo },
           lastConnectionDate: { $gte: dateWithXdaysAgo },
-        }).count(); // KPI 5
+        }).length; // KPI 5
         metricsRes +=
         metricsRes +=
           'wekan_usersWithLastConnectionDated30DaysAgo ' + resCount + '\n';
           'wekan_usersWithLastConnectionDated30DaysAgo ' + resCount + '\n';
         resCount = 0;
         resCount = 0;

+ 12 - 12
models/users.js

@@ -512,9 +512,9 @@ Users.allow({
     return doc._id === userId;
     return doc._id === userId;
   },
   },
   remove(userId, doc) {
   remove(userId, doc) {
-    const adminsNumber = Users.find({
+    const adminsNumber = ReactiveCache.getUsers({
       isAdmin: true,
       isAdmin: true,
-    }).count();
+    }).length;
     const isAdmin = ReactiveCache.getUser(
     const isAdmin = ReactiveCache.getUser(
       {
       {
         _id: userId,
         _id: userId,
@@ -1242,12 +1242,12 @@ if (Meteor.isServer) {
       check(userOrgsArray, Array);
       check(userOrgsArray, Array);
       check(userTeamsArray, Array);
       check(userTeamsArray, Array);
       if (ReactiveCache.getCurrentUser()?.isAdmin) {
       if (ReactiveCache.getCurrentUser()?.isAdmin) {
-        const nUsersWithUsername = Users.find({
+        const nUsersWithUsername = ReactiveCache.getUsers({
           username,
           username,
-        }).count();
-        const nUsersWithEmail = Users.find({
+        }).length;
+        const nUsersWithEmail = ReactiveCache.getUsers({
           email,
           email,
-        }).count();
+        }).length;
         if (nUsersWithUsername > 0) {
         if (nUsersWithUsername > 0) {
           throw new Meteor.Error('username-already-taken');
           throw new Meteor.Error('username-already-taken');
         } else if (nUsersWithEmail > 0) {
         } else if (nUsersWithEmail > 0) {
@@ -1282,9 +1282,9 @@ if (Meteor.isServer) {
       check(username, String);
       check(username, String);
       check(userId, String);
       check(userId, String);
       if (ReactiveCache.getCurrentUser()?.isAdmin) {
       if (ReactiveCache.getCurrentUser()?.isAdmin) {
-        const nUsersWithUsername = Users.find({
+        const nUsersWithUsername = ReactiveCache.getUsers({
           username,
           username,
-        }).count();
+        }).length;
         if (nUsersWithUsername > 0) {
         if (nUsersWithUsername > 0) {
           throw new Meteor.Error('username-already-taken');
           throw new Meteor.Error('username-already-taken');
         } else {
         } else {
@@ -1539,7 +1539,7 @@ if (Meteor.isServer) {
       check(teamId, String);
       check(teamId, String);
       check(teamDisplayName, String);
       check(teamDisplayName, String);
       if (ReactiveCache.getCurrentUser()?.isAdmin) {
       if (ReactiveCache.getCurrentUser()?.isAdmin) {
-        Users.find({
+        ReactiveCache.getUsers({
           teams: {
           teams: {
             $elemMatch: { teamId: teamId },
             $elemMatch: { teamId: teamId },
           },
           },
@@ -1564,7 +1564,7 @@ if (Meteor.isServer) {
       check(orgId, String);
       check(orgId, String);
       check(orgDisplayName, String);
       check(orgDisplayName, String);
       if (ReactiveCache.getCurrentUser()?.isAdmin) {
       if (ReactiveCache.getCurrentUser()?.isAdmin) {
-        Users.find({
+        ReactiveCache.getUsers({
           orgs: {
           orgs: {
             $elemMatch: { orgId: orgId },
             $elemMatch: { orgId: orgId },
           },
           },
@@ -1587,7 +1587,7 @@ if (Meteor.isServer) {
     },
     },
   });
   });
   Accounts.onCreateUser((options, user) => {
   Accounts.onCreateUser((options, user) => {
-    const userCount = Users.find().count();
+    const userCount = ReactiveCache.getUsers().length;
     if (userCount === 0) {
     if (userCount === 0) {
       user.isAdmin = true;
       user.isAdmin = true;
     }
     }
@@ -1715,7 +1715,7 @@ const addCronJob = _.debounce(
       name: 'notification_cleanup',
       name: 'notification_cleanup',
       schedule: (parser) => parser.text('every 1 days'),
       schedule: (parser) => parser.text('every 1 days'),
       job: () => {
       job: () => {
-        for (const user of Users.find()) {
+        for (const user of ReactiveCache.getUsers()) {
           if (!user.profile || !user.profile.notifications) continue;
           if (!user.profile || !user.profile.notifications) continue;
           for (const notification of user.profile.notifications) {
           for (const notification of user.profile.notifications) {
             if (notification.read) {
             if (notification.read) {