diff --git a/models/boards.js b/models/boards.js index 66a4389c0..7821a353d 100644 --- a/models/boards.js +++ b/models/boards.js @@ -1556,10 +1556,10 @@ Boards.uniqueTitle = title => { ); const base = escapeForRegex(m.groups.title); const baseTitle = m.groups.title; - boards = Boards.find({ title: new RegExp(`^${base}\\s*(\\[(?\\d+)]\\s*$|\\s*$)`) }); - if (boards.count() > 0) { + boards = ReactiveCache.getBoards({ title: new RegExp(`^${base}\\s*(\\[(?\\d+)]\\s*$|\\s*$)`) }); + if (boards.length > 0) { let num = 0; - Boards.find({ title: new RegExp(`^${base}\\s*\\[\\d+]\\s*$`) }).forEach( + ReactiveCache.getBoards({ title: new RegExp(`^${base}\\s*\\[\\d+]\\s*$`) }).forEach( board => { const m = board.title.match( new RegExp('^(?.*?)\\s*\\[(?<num>\\d+)]\\s*$'), @@ -1589,7 +1589,8 @@ Boards.userSearch = ( if (userId) { selector.$or.push({ members: { $elemMatch: { userId, isActive: true } } }); } - return Boards.find(selector, projection); + const ret = ReactiveCache.getBoards(selector, projection); + return ret; }; Boards.userBoards = ( @@ -1617,7 +1618,7 @@ Boards.userBoards = ( { teams: { $elemMatch: { teamId: { $in: user.teamIds() }, isActive: true } } }, ]; - return Boards.find(selector, projection); + return ReactiveCache.getBoards(selector, projection); }; Boards.userBoardIds = (userId, archived = false, selector = {}) => { @@ -1972,7 +1973,7 @@ if (Meteor.isServer) { req.userId === paramUserId, ); - const data = Boards.find( + const data = ReactiveCache.getBoards( { archived: false, 'members.userId': paramUserId, @@ -2008,7 +2009,7 @@ if (Meteor.isServer) { Authentication.checkUserId(req.userId); JsonRoutes.sendResult(res, { code: 200, - data: Boards.find( + data: ReactiveCache.getBoards( { permission: 'public' }, { sort: { sort: 1 /* boards default sorting */ }, @@ -2040,8 +2041,8 @@ if (Meteor.isServer) { JsonRoutes.sendResult(res, { code: 200, data: { - private: Boards.find({ permission: 'private' }).count(), - public: Boards.find({ permission: 'public' }).count(), + private: ReactiveCache.getBoards({ permission: 'private' }).length, + public: ReactiveCache.getBoards({ permission: 'public' }).length, }, }); } catch (error) { diff --git a/models/customFields.js b/models/customFields.js index 53d8201c3..8e085eb04 100644 --- a/models/customFields.js +++ b/models/customFields.js @@ -170,25 +170,25 @@ CustomFields.allow({ insert(userId, doc) { return allowIsAnyBoardMember( userId, - Boards.find({ + ReactiveCache.getBoards({ _id: { $in: doc.boardIds }, - }).fetch(), + }), ); }, update(userId, doc) { return allowIsAnyBoardMember( userId, - Boards.find({ + ReactiveCache.getBoards({ _id: { $in: doc.boardIds }, - }).fetch(), + }), ); }, remove(userId, doc) { return allowIsAnyBoardMember( userId, - Boards.find({ + ReactiveCache.getBoards({ _id: { $in: doc.boardIds }, - }).fetch(), + }), ); }, fetch: ['userId', 'boardIds'], diff --git a/models/server/metrics.js b/models/server/metrics.js index bc4ebe84b..f60e678d0 100644 --- a/models/server/metrics.js +++ b/models/server/metrics.js @@ -33,7 +33,8 @@ const getBoardTitleWithMostActivities = (dateWithXdaysAgo, nbLimit) => { }; const getBoards = (boardIds) => { - return Boards.find({ _id: { $in: boardIds } }).fetch(); + const ret = ReactiveCache.getBoards({ _id: { $in: boardIds } }); + return ret; }; Meteor.startup(() => { WebApp.connectHandlers.use('/metrics', (req, res, next) => { @@ -77,7 +78,7 @@ Meteor.startup(() => { metricsRes += '# Number of registered boards\n'; // Get number of registered boards - resCount = Boards.find({ archived: false, type: 'board' }).count(); // KPI 3 + resCount = ReactiveCache.getBoards({ archived: false, type: 'board' }).length; // KPI 3 metricsRes += 'wekan_registeredboards ' + resCount + '\n'; resCount = 0; @@ -86,7 +87,7 @@ Meteor.startup(() => { // Get number of registered boards by registered users resCount = - Boards.find({ archived: false, type: 'board' }).count() / + ReactiveCache.getBoards({ archived: false, type: 'board' }).length / ReactiveCache.getUsers({}).length; // KPI 4 metricsRes += 'wekan_registeredboardsBysRegisteredUsers ' + resCount + '\n'; @@ -96,11 +97,11 @@ Meteor.startup(() => { metricsRes += '# Number of registered boards\n'; // Get board numbers with only one member - resCount = Boards.find({ + resCount = ReactiveCache.getBoards({ archived: false, type: 'board', members: { $size: 1 }, - }).count(); // KPI 5 + }).length; // KPI 5 metricsRes += 'wekan_registeredboardsWithOnlyOneMember ' + resCount + '\n'; resCount = 0; diff --git a/models/users.js b/models/users.js index d8487934e..9191c13b8 100644 --- a/models/users.js +++ b/models/users.js @@ -2029,7 +2029,7 @@ if (Meteor.isServer) { delete data.services; // get all boards where the user is member of - let boards = Boards.find( + let boards = ReactiveCache.getBoards( { type: 'board', 'members.userId': req.userId, @@ -2115,7 +2115,7 @@ if (Meteor.isServer) { } // get all boards where the user is member of - let boards = Boards.find( + let boards = ReactiveCache.getBoards( { type: 'board', 'members.userId': id, @@ -2174,7 +2174,7 @@ if (Meteor.isServer) { }); if (data !== undefined) { if (action === 'takeOwnership') { - data = Boards.find( + data = ReactiveCache.getBoards( { 'members.userId': id, 'members.isAdmin': true, @@ -2268,7 +2268,7 @@ if (Meteor.isServer) { let data = ReactiveCache.getUser(userId); if (data !== undefined) { if (action === 'add') { - data = Boards.find({ + data = ReactiveCache.getBoards({ _id: boardId, }).map(function (board) { if (!board.hasMember(userId)) { @@ -2329,7 +2329,7 @@ if (Meteor.isServer) { let data = ReactiveCache.getUser(userId); if (data !== undefined) { if (action === 'remove') { - data = Boards.find({ + data = ReactiveCache.getBoards({ _id: boardId, }).map(function (board) { if (board.hasMember(userId)) { diff --git a/server/publications/cards.js b/server/publications/cards.js index 37c7ff845..1d83298b2 100644 --- a/server/publications/cards.js +++ b/server/publications/cards.js @@ -245,7 +245,7 @@ function buildSelector(queryParams) { const boards = Boards.userSearch(userId, { title: new RegExp(escapeForRegex(query), 'i'), }); - if (boards.count()) { + if (boards.length) { boards.forEach(board => { queryBoards.push(board._id); }); @@ -372,7 +372,7 @@ function buildSelector(queryParams) { labels: { $elemMatch: { color: label.toLowerCase() } }, }); - if (boards.count()) { + if (boards.length) { boards.forEach(board => { // eslint-disable-next-line no-console // console.log('board:', board); @@ -396,7 +396,7 @@ function buildSelector(queryParams) { labels: { $elemMatch: { name: reLabel } }, }); - if (boards.count()) { + if (boards.length) { boards.forEach(board => { board.labels .filter(boardLabel => {