From 4115d62bac882ceaaec531b1f9df2666097be51a Mon Sep 17 00:00:00 2001 From: Lauri Ojansivu Date: Sat, 16 Jan 2021 03:10:20 +0200 Subject: [PATCH] Limit amount of data in publications where possible. Thanks to xet7 ! --- server/publications/cards.js | 65 +++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 5 deletions(-) diff --git a/server/publications/cards.js b/server/publications/cards.js index a1fef2696..ba60d3dc1 100644 --- a/server/publications/cards.js +++ b/server/publications/cards.js @@ -72,7 +72,18 @@ Meteor.publish('myCards', function() { Boards.find({ _id: { $in: boards } }), Swimlanes.find({ _id: { $in: swimlanes } }), Lists.find({ _id: { $in: lists } }), - Users.find({ _id: { $in: users } }), + Users.find( + { _id: { $in: users } }, + { + fields: { + _id: 1, + username: 1, + 'profile.fullname': 1, + 'profile.avatarUrl': 1, + 'profile.initials': 1, + }, + }, + ), ]; }); @@ -82,7 +93,18 @@ Meteor.publish('dueCards', function(allUsers = false) { // eslint-disable-next-line no-console // console.log('all users:', allUsers); - const user = Users.findOne(this.userId); + const user = Users.findOne( + { _id: this.userId }, + { + fields: { + _id: 1, + username: 1, + 'profile.fullname': 1, + 'profile.avatarUrl': 1, + 'profile.initials': 1, + }, + }, + ); const archivedBoards = []; Boards.find({ archived: true }).forEach(board => { @@ -171,7 +193,18 @@ Meteor.publish('dueCards', function(allUsers = false) { Boards.find({ _id: { $in: boards } }), Swimlanes.find({ _id: { $in: swimlanes } }), Lists.find({ _id: { $in: lists } }), - Users.find({ _id: { $in: users } }), + Users.find( + { _id: { $in: users } }, + { + fields: { + _id: 1, + username: 1, + 'profile.fullname': 1, + 'profile.avatarUrl': 1, + 'profile.initials': 1, + }, + }, + ), ]; }); @@ -216,7 +249,18 @@ Meteor.publish('globalSearch', function(queryParams) { }); Meteor.publish('brokenCards', function() { - const user = Users.findOne(this.userId); + const user = Users.findOne( + { _id: this.userId }, + { + fields: { + _id: 1, + username: 1, + 'profile.fullname': 1, + 'profile.avatarUrl': 1, + 'profile.initials': 1, + }, + }, + ); const permiitedBoards = [null]; let selector = {}; @@ -284,6 +328,17 @@ Meteor.publish('brokenCards', function() { Boards.find({ _id: { $in: boards } }), Swimlanes.find({ _id: { $in: swimlanes } }), Lists.find({ _id: { $in: lists } }), - Users.find({ _id: { $in: users } }), + Users.find( + { _id: { $in: users } }, + { + fields: { + _id: 1, + username: 1, + 'profile.fullname': 1, + 'profile.avatarUrl': 1, + 'profile.initials': 1, + }, + }, + ), ]; });