Kaynağa Gözat

Move every Boards.findOne(boardId) to the ReactiveCache (Part 2)

Martin Filser 2 yıl önce
ebeveyn
işleme
a182482cfb

+ 2 - 1
client/components/activities/activities.js

@@ -1,3 +1,4 @@
+import { ReactiveCache } from '/imports/reactiveCache';
 import DOMPurify from 'dompurify';
 import { TAPi18n } from '/imports/i18n';
 
@@ -145,7 +146,7 @@ BlazeComponent.extendComponent({
   lastLabel() {
     const lastLabelId = this.currentData().activity.labelId;
     if (!lastLabelId) return null;
-    const lastLabel = Boards.findOne(
+    const lastLabel = ReactiveCache.getBoard(
       this.currentData().activity.boardId,
     ).getLabelById(lastLabelId);
     if (lastLabel && (lastLabel.name === undefined || lastLabel.name === '')) {

+ 5 - 4
client/components/boards/boardsList.js

@@ -1,3 +1,4 @@
+import { ReactiveCache } from '/imports/reactiveCache';
 import { TAPi18n } from '/imports/i18n';
 
 const subManager = new SubsManager();
@@ -223,8 +224,8 @@ BlazeComponent.extendComponent({
   boardMembers(boardId) {
     let boardMembers = [];
     /* Bug Board icons random dance https://github.com/wekan/wekan/issues/4214
-    const lists = Boards.findOne({ '_id': boardId })
-    let members = lists.members;
+    const lists = ReactiveCache.getBoard(boardId)
+    let members = lists.members
     members.forEach(member => {
       boardMembers.push(member.userId);
     });
@@ -266,14 +267,14 @@ BlazeComponent.extendComponent({
           evt.preventDefault();
         },
         'click .js-clone-board'(evt) {
-          let title = getSlug(Boards.findOne(this.currentData()._id).title) || 'cloned-board';
+          let title = getSlug(ReactiveCache.getBoard(this.currentData()._id).title) || 'cloned-board';
           Meteor.call(
             'copyBoard',
             this.currentData()._id,
             {
               sort: Boards.find({ archived: false }).count(),
               type: 'board',
-              title: Boards.findOne(this.currentData()._id).title,
+              title: ReactiveCache.getBoard(this.currentData()._id).title,
             },
             (err, res) => {
               if (err) {

+ 2 - 1
client/components/cards/cardDetails.js

@@ -1,3 +1,4 @@
+import { ReactiveCache } from '/imports/reactiveCache';
 import moment from 'moment/min/moment-with-locales';
 import { TAPi18n } from '/imports/i18n';
 import { DatePicker } from '/client/lib/datepicker';
@@ -143,7 +144,7 @@ BlazeComponent.extendComponent({
     const card = this.currentData();
     let result = '#';
     if (card) {
-      const board = Boards.findOne(card.boardId);
+      const board = ReactiveCache.getBoard(card.boardId);
       if (board) {
         result = FlowRouter.path('card', {
           boardId: card.boardId,

+ 3 - 2
client/components/cards/checklists.js

@@ -1,3 +1,4 @@
+import { ReactiveCache } from '/imports/reactiveCache';
 import { TAPi18n } from '/imports/i18n';
 import Cards from '/models/cards';
 import Boards from '/models/boards';
@@ -243,12 +244,12 @@ BlazeComponent.extendComponent({
   },
 
   swimlanes() {
-    const board = Boards.findOne(this.selectedBoardId.get());
+    const board = ReactiveCache.getBoard(this.selectedBoardId.get());
     return board.swimlanes();
   },
 
   aBoardLists() {
-    const board = Boards.findOne(this.selectedBoardId.get());
+    const board = ReactiveCache.getBoard(this.selectedBoardId.get());
     return board.lists();
   },
 

+ 3 - 1
client/components/cards/subtasks.js

@@ -1,3 +1,5 @@
+import { ReactiveCache } from '/imports/reactiveCache';
+
 BlazeComponent.extendComponent({
   addSubtask(event) {
     event.preventDefault();
@@ -6,7 +8,7 @@ BlazeComponent.extendComponent({
     const cardId = this.currentData().cardId;
     const card = Cards.findOne(cardId);
     const sortIndex = -1;
-    const crtBoard = Boards.findOne(card.boardId);
+    const crtBoard = ReactiveCache.getBoard(card.boardId);
     const targetBoard = crtBoard.getDefaultSubtasksBoard();
     const listId = targetBoard.getDefaultSubtasksListId();
 

+ 7 - 7
client/components/lists/listBody.js

@@ -1,3 +1,4 @@
+import { ReactiveCache } from '/imports/reactiveCache';
 import { TAPi18n } from '/imports/i18n';
 import { Spinner } from '/client/lib/spinner';
 
@@ -269,7 +270,7 @@ BlazeComponent.extendComponent({
     const currentBoardId = Session.get('currentBoard');
     arr = [];
     _.forEach(
-      Boards.findOne(currentBoardId)
+      ReactiveCache.getBoard(currentBoardId)
         .customFields()
         .fetch(),
       function (field) {
@@ -288,8 +289,8 @@ BlazeComponent.extendComponent({
 
   getLabels() {
     const currentBoardId = Session.get('currentBoard');
-    if (Boards.findOne(currentBoardId).labels) {
-      return Boards.findOne(currentBoardId).labels.filter(label => {
+    if (ReactiveCache.getBoard(currentBoardId).labels) {
+      return ReactiveCache.getBoard(currentBoardId).labels.filter(label => {
         return this.labels.get().indexOf(label._id) > -1;
       });
     }
@@ -430,7 +431,7 @@ BlazeComponent.extendComponent({
     this.boardId = Session.get('currentBoard');
     // In order to get current board info
     subManager.subscribe('board', this.boardId, false);
-    this.board = Boards.findOne(this.boardId);
+    this.board = ReactiveCache.getBoard(this.boardId);
     // List where to insert card
     const list = $(Popup._getTopStack().openerElement).closest('.js-list');
     this.listId = Blaze.getData(list[0])._id;
@@ -589,7 +590,6 @@ BlazeComponent.extendComponent({
       this.isBoardTemplateSearch;
     let board = {};
     if (this.isTemplateSearch) {
-      //board = Boards.findOne((Meteor.user().profile || {}).templatesBoardId);
       board._id = (Meteor.user().profile || {}).templatesBoardId;
     } else {
       // Prefetch first non-current board id
@@ -651,7 +651,7 @@ BlazeComponent.extendComponent({
     if (!this.selectedBoardId) {
       return [];
     }
-    const board = Boards.findOne(this.selectedBoardId.get());
+    const board = ReactiveCache.getBoard(this.selectedBoardId.get());
     if (!this.isTemplateSearch || this.isCardTemplateSearch) {
       return board.searchCards(this.term.get(), false);
     } else if (this.isListTemplateSearch) {
@@ -713,7 +713,7 @@ BlazeComponent.extendComponent({
             element.type = 'list';
             _id = element.copy(this.boardId, this.swimlaneId);
           } else if (this.isSwimlaneTemplateSearch) {
-            element.sort = Boards.findOne(this.boardId)
+            element.sort = ReactiveCache.getBoard(this.boardId)
               .swimlanes()
               .count();
             element.type = 'swimlane';

+ 3 - 2
client/components/settings/attachments.js

@@ -1,3 +1,4 @@
+import { ReactiveCache } from '/imports/reactiveCache';
 import Attachments, { fileStoreStrategyFactory } from '/models/attachments';
 const filesize = require('filesize');
 
@@ -61,14 +62,14 @@ BlazeComponent.extendComponent({
               return _version;
             });
         });
-        const board = Boards.findOne(boardId);
+        const board = ReactiveCache.getBoard(boardId);
         board.attachments = boardAttachments;
         return board;
       })
     return ret;
   },
   getBoardData(boardid) {
-    const ret = Boards.findOne(boardId);
+    const ret = ReactiveCache.getBoard(boardId);
     return ret;
   },
   events() {

+ 2 - 1
client/components/sidebar/sidebar.js

@@ -1,3 +1,4 @@
+import { ReactiveCache } from '/imports/reactiveCache';
 import { TAPi18n } from '/imports/i18n';
 
 Sidebar = null;
@@ -284,7 +285,7 @@ Template.memberPopup.events({
     Cards.find({ boardId, assignees: memberId }).forEach(card => {
       card.unassignAssignee(memberId);
     });
-    Boards.findOne(boardId).removeMember(memberId);
+    ReactiveCache.getBoard(boardId).removeMember(memberId);
     Popup.back();
   }),
   'click .js-leave-member': Popup.afterConfirm('leaveBoard', () => {

+ 6 - 4
client/lib/dialogWithBoardSwimlaneList.js

@@ -1,3 +1,5 @@
+import { ReactiveCache } from '/imports/reactiveCache';
+
 export class DialogWithBoardSwimlaneList extends BlazeComponent {
   /** returns the card dialog options
    * @return Object with properties { boardId, swimlaneId, listId }
@@ -62,7 +64,7 @@ export class DialogWithBoardSwimlaneList extends BlazeComponent {
   /** sets the first swimlane id */
   setFirstSwimlaneId() {
     try {
-      const board = Boards.findOne(this.selectedBoardId.get());
+      const board = ReactiveCache.getBoard(this.selectedBoardId.get());
       const swimlaneId = board.swimlanes().fetch()[0]._id;
       this.selectedSwimlaneId.set(swimlaneId);
     } catch (e) {}
@@ -70,7 +72,7 @@ export class DialogWithBoardSwimlaneList extends BlazeComponent {
   /** sets the first list id */
   setFirstListId() {
     try {
-      const board = Boards.findOne(this.selectedBoardId.get());
+      const board = ReactiveCache.getBoard(this.selectedBoardId.get());
       const listId = board.lists().fetch()[0]._id;
       this.selectedListId.set(listId);
     } catch (e) {}
@@ -120,14 +122,14 @@ export class DialogWithBoardSwimlaneList extends BlazeComponent {
 
   /** returns all available swimlanes of the current board */
   swimlanes() {
-    const board = Boards.findOne(this.selectedBoardId.get());
+    const board = ReactiveCache.getBoard(this.selectedBoardId.get());
     const ret = board.swimlanes();
     return ret;
   }
 
   /** returns all available lists of the current board */
   lists() {
-    const board = Boards.findOne(this.selectedBoardId.get());
+    const board = ReactiveCache.getBoard(this.selectedBoardId.get());
     const ret = board.lists();
     return ret;
   }

+ 4 - 2
client/lib/keyboard.js

@@ -1,3 +1,5 @@
+import { ReactiveCache } from '/imports/reactiveCache';
+
 // XXX There is no reason to define these shortcuts globally, they should be
 // attached to a template (most of them will go in the `board` template).
 
@@ -76,7 +78,7 @@ Mousetrap.bind(numbArray, (evt, key) => {
     return;
   }
   const currentBoardId = Session.get('currentBoard');
-  board = Boards.findOne(currentBoardId);
+  board = ReactiveCache.getBoard(currentBoardId);
   labels = board.labels;
   if(MultiSelection.isActive())
   {
@@ -100,7 +102,7 @@ Mousetrap.bind(numArray, (evt, key) => {
   if (currentUserId === null) {
     return;
   }
-  board = Boards.findOne(currentBoardId);
+  board = ReactiveCache.getBoard(currentBoardId);
   labels = board.labels;
   if(MultiSelection.isActive() && Meteor.user().isBoardMember())
   {

+ 2 - 2
client/lib/utils.js

@@ -201,7 +201,7 @@ Utils = {
 
   // XXX We should remove these two methods
   goBoardId(_id) {
-    const board = Boards.findOne(_id);
+    const board = ReactiveCache.getBoard(_id);
     return (
       board &&
       FlowRouter.go('board', {
@@ -213,7 +213,7 @@ Utils = {
 
   goCardId(_id) {
     const card = Cards.findOne(_id);
-    const board = Boards.findOne(card.boardId);
+    const board = ReactiveCache.getBoard(card.boardId);
     return (
       board &&
       FlowRouter.go('card', {

+ 4 - 3
models/actions.js

@@ -1,16 +1,17 @@
+import { ReactiveCache } from '/imports/reactiveCache';
 import { Meteor } from 'meteor/meteor';
 
 Actions = new Mongo.Collection('actions');
 
 Actions.allow({
   insert(userId, doc) {
-    return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
+    return allowIsBoardAdmin(userId, ReactiveCache.getBoard(doc.boardId));
   },
   update(userId, doc) {
-    return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
+    return allowIsBoardAdmin(userId, ReactiveCache.getBoard(doc.boardId));
   },
   remove(userId, doc) {
-    return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
+    return allowIsBoardAdmin(userId, ReactiveCache.getBoard(doc.boardId));
   },
 });
 

+ 5 - 3
models/activities.js

@@ -1,3 +1,5 @@
+import { ReactiveCache } from '/imports/reactiveCache';
+
 // Activities don't need a schema because they are always set from the a trusted
 // environment - the server - and there is no risk that a user change the logic
 // we use with this collection. Moreover using a schema for this collection
@@ -12,10 +14,10 @@ Activities = new Mongo.Collection('activities');
 
 Activities.helpers({
   board() {
-    return Boards.findOne(this.boardId);
+    return ReactiveCache.getBoard(this.boardId);
   },
   oldBoard() {
-    return Boards.findOne(this.oldBoardId);
+    return ReactiveCache.getBoard(this.oldBoardId);
   },
   user() {
     return Users.findOne(this.userId);
@@ -108,7 +110,7 @@ if (Meteor.isServer) {
     let participants = [];
     let watchers = [];
     let title = 'act-activity-notify';
-    const board = Boards.findOne(activity.boardId);
+    const board = ReactiveCache.getBoard(activity.boardId);
     const description = `act-${activity.activityType}`;
     const params = {
       activityId: activity._id,

+ 5 - 4
models/attachments.js

@@ -1,3 +1,4 @@
+import { ReactiveCache } from '/imports/reactiveCache';
 import { Meteor } from 'meteor/meteor';
 import { FilesCollection } from 'meteor/ostrio:files';
 import { isFileValid } from './fileValidation';
@@ -122,7 +123,7 @@ Attachments = new FilesCollection({
       return false;
     }
 
-    const board = Boards.findOne(fileObj.meta.boardId);
+    const board = ReactiveCache.getBoard(fileObj.meta.boardId);
     if (board.isPublic()) {
       return true;
     }
@@ -134,13 +135,13 @@ Attachments = new FilesCollection({
 if (Meteor.isServer) {
   Attachments.allow({
     insert(userId, fileObj) {
-      return allowIsBoardMember(userId, Boards.findOne(fileObj.boardId));
+      return allowIsBoardMember(userId, ReactiveCache.getBoard(fileObj.boardId));
     },
     update(userId, fileObj) {
-      return allowIsBoardMember(userId, Boards.findOne(fileObj.boardId));
+      return allowIsBoardMember(userId, ReactiveCache.getBoard(fileObj.boardId));
     },
     remove(userId, fileObj) {
-      return allowIsBoardMember(userId, Boards.findOne(fileObj.boardId));
+      return allowIsBoardMember(userId, ReactiveCache.getBoard(fileObj.boardId));
     },
     fetch: ['meta'],
   });

+ 6 - 4
models/attachments_old.js

@@ -1,3 +1,5 @@
+import { ReactiveCache } from '/imports/reactiveCache';
+
 const storeName = 'attachments';
 const defaultStoreOptions = {
   beforeWrite: fileObj => {
@@ -35,19 +37,19 @@ if (Meteor.isServer) {
 
   AttachmentsOld.allow({
     insert(userId, doc) {
-      return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
+      return allowIsBoardMember(userId, ReactiveCache.getBoard(doc.boardId));
     },
     update(userId, doc) {
-      return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
+      return allowIsBoardMember(userId, ReactiveCache.getBoard(doc.boardId));
     },
     remove(userId, doc) {
-      return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
+      return allowIsBoardMember(userId, ReactiveCache.getBoard(doc.boardId));
     },
     // We authorize the attachment download either:
     // - if the board is public, everyone (even unconnected) can download it
     // - if the board is private, only board members can download it
     download(userId, doc) {
-      const board = Boards.findOne(doc.boardId);
+      const board = ReactiveCache.getBoard(doc.boardId);
       if (board.isPublic()) {
         return true;
       } else {

+ 6 - 5
models/boards.js

@@ -1,3 +1,4 @@
+import { ReactiveCache } from '/imports/reactiveCache';
 import escapeForRegex from 'escape-string-regexp';
 import { TAPi18n } from '/imports/i18n';
 import {
@@ -1124,7 +1125,7 @@ Boards.helpers({
   },
 
   getDefaultSubtasksBoard() {
-    return Boards.findOne(this.getDefaultSubtasksBoardId());
+    return ReactiveCache.getBoard(this.getDefaultSubtasksBoardId());
   },
 
   //Date Settings option such as received date, start date and so on.
@@ -1157,7 +1158,7 @@ Boards.helpers({
   },
 
   getDefaultDateSettingsBoard() {
-    return Boards.findOne(this.getDefaultDateSettingsBoardId());
+    return ReactiveCache.getBoard(this.getDefaultDateSettingsBoardId());
   },
 
   getDefaultSubtasksListId() {
@@ -1696,7 +1697,7 @@ if (Meteor.isServer) {
     },
     quitBoard(boardId) {
       check(boardId, String);
-      const board = Boards.findOne(boardId);
+      const board = ReactiveCache.getBoard(boardId);
       if (board) {
         const userId = Meteor.userId();
         const index = board.memberIndex(userId);
@@ -1708,7 +1709,7 @@ if (Meteor.isServer) {
     },
     acceptInvite(boardId) {
       check(boardId, String);
-      const board = Boards.findOne(boardId);
+      const board = ReactiveCache.getBoard(boardId);
       if (!board) {
         throw new Meteor.Error('error-board-doesNotExist');
       }
@@ -1749,7 +1750,7 @@ if (Meteor.isServer) {
   Meteor.methods({
     archiveBoard(boardId) {
       check(boardId, String);
-      const board = Boards.findOne(boardId);
+      const board = ReactiveCache.getBoard(boardId);
       if (board) {
         const userId = Meteor.userId();
         const index = board.memberIndex(userId);

+ 5 - 3
models/cardCommentReactions.js

@@ -1,3 +1,5 @@
+import { ReactiveCache } from '/imports/reactiveCache';
+
 const commentReactionSchema = new SimpleSchema({
   reactionCodepoint: {
     type: String,
@@ -49,13 +51,13 @@ CardCommentReactions.attachSchema(
 
 CardCommentReactions.allow({
   insert(userId, doc) {
-    return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
+    return allowIsBoardMember(userId, ReactiveCache.getBoard(doc.boardId));
   },
   update(userId, doc) {
-    return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
+    return allowIsBoardMember(userId, ReactiveCache.getBoard(doc.boardId));
   },
   remove(userId, doc) {
-    return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
+    return allowIsBoardMember(userId, ReactiveCache.getBoard(doc.boardId));
   },
   fetch: ['boardId'],
 });

+ 4 - 3
models/cardComments.js

@@ -1,3 +1,4 @@
+import { ReactiveCache } from '/imports/reactiveCache';
 import escapeForRegex from 'escape-string-regexp';
 import DOMPurify from 'dompurify';
 
@@ -74,13 +75,13 @@ CardComments.attachSchema(
 
 CardComments.allow({
   insert(userId, doc) {
-    return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
+    return allowIsBoardMember(userId, ReactiveCache.getBoard(doc.boardId));
   },
   update(userId, doc) {
-    return userId === doc.userId || allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
+    return userId === doc.userId || allowIsBoardAdmin(userId, ReactiveCache.getBoard(doc.boardId));
   },
   remove(userId, doc) {
-    return userId === doc.userId || allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
+    return userId === doc.userId || allowIsBoardAdmin(userId, ReactiveCache.getBoard(doc.boardId));
   },
   fetch: ['userId', 'boardId'],
 });

+ 33 - 35
models/cards.js

@@ -490,19 +490,19 @@ Cards.attachSchema(
 
 Cards.allow({
   insert(userId, doc) {
-    return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
+    return allowIsBoardMember(userId, ReactiveCache.getBoard(doc.boardId));
   },
 
   update(userId, doc, fields) {
     // Allow board members or logged in users if only vote get's changed
     return (
-      allowIsBoardMember(userId, Boards.findOne(doc.boardId)) ||
+      allowIsBoardMember(userId, ReactiveCache.getBoard(doc.boardId)) ||
       (_.isEqual(fields, ['vote', 'modifiedAt', 'dateLastActivity']) &&
         !!userId)
     );
   },
   remove(userId, doc) {
-    return allowIsBoardMember(userId, Boards.findOne(doc.boardId));
+    return allowIsBoardMember(userId, ReactiveCache.getBoard(doc.boardId));
   },
   fetch: ['boardId'],
 });
@@ -1093,7 +1093,7 @@ Cards.helpers({
       if (card && card.description) return card.description;
       else return null;
     } else if (this.isLinkedBoard()) {
-      const board = Boards.findOne({ _id: this.linkedId });
+      const board = ReactiveCache.getBoard(this.linkedId);
       if (board && board.description) return board.description;
       else return null;
     } else if (this.description) {
@@ -1112,7 +1112,7 @@ Cards.helpers({
         return card.members;
       }
     } else if (this.isLinkedBoard()) {
-      const board = Boards.findOne({ _id: this.linkedId });
+      const board = ReactiveCache.getBoard(this.linkedId);
       if (board === undefined) {
         return null;
       } else {
@@ -1134,7 +1134,7 @@ Cards.helpers({
         return card.assignees;
       }
     } else if (this.isLinkedBoard()) {
-      const board = Boards.findOne({ _id: this.linkedId });
+      const board = ReactiveCache.getBoard(this.linkedId);
       if (board === undefined) {
         return null;
       } else {
@@ -1150,7 +1150,7 @@ Cards.helpers({
   assignMember(memberId) {
     let ret;
     if (this.isLinkedBoard()) {
-      const board = Boards.findOne({ _id: this.linkedId });
+      const board = ReactiveCache.getBoard(this.linkedId);
       ret = board.addMember(memberId);
     } else {
       ret = Cards.update(
@@ -1168,7 +1168,7 @@ Cards.helpers({
         { $addToSet: { assignees: assigneeId } },
       );
     } else if (this.isLinkedBoard()) {
-      const board = Boards.findOne({ _id: this.linkedId });
+      const board = ReactiveCache.getBoard(this.linkedId);
       return board.addAssignee(assigneeId);
     } else {
       return Cards.update(
@@ -1185,7 +1185,7 @@ Cards.helpers({
         { $pull: { members: memberId } },
       );
     } else if (this.isLinkedBoard()) {
-      const board = Boards.findOne({ _id: this.linkedId });
+      const board = ReactiveCache.getBoard(this.linkedId);
       return board.removeMember(memberId);
     } else {
       return Cards.update({ _id: this._id }, { $pull: { members: memberId } });
@@ -1199,7 +1199,7 @@ Cards.helpers({
         { $pull: { assignees: assigneeId } },
       );
     } else if (this.isLinkedBoard()) {
-      const board = Boards.findOne({ _id: this.linkedId });
+      const board = ReactiveCache.getBoard(this.linkedId);
       return board.removeAssignee(assigneeId);
     } else {
       return Cards.update(
@@ -1234,7 +1234,7 @@ Cards.helpers({
         return card.receivedAt;
       }
     } else if (this.isLinkedBoard()) {
-      const board = Boards.findOne({ _id: this.linkedId });
+      const board = ReactiveCache.getBoard(this.linkedId);
       if (board === undefined) {
         return null;
       } else {
@@ -1262,7 +1262,7 @@ Cards.helpers({
         return card.startAt;
       }
     } else if (this.isLinkedBoard()) {
-      const board = Boards.findOne({ _id: this.linkedId });
+      const board = ReactiveCache.getBoard(this.linkedId);
       if (board === undefined) {
         return null;
       } else {
@@ -1290,7 +1290,7 @@ Cards.helpers({
         return card.dueAt;
       }
     } else if (this.isLinkedBoard()) {
-      const board = Boards.findOne({ _id: this.linkedId });
+      const board = ReactiveCache.getBoard(this.linkedId);
       if (board === undefined) {
         return null;
       } else {
@@ -1318,7 +1318,7 @@ Cards.helpers({
         return card.endAt;
       }
     } else if (this.isLinkedBoard()) {
-      const board = Boards.findOne({ _id: this.linkedId });
+      const board = ReactiveCache.getBoard(this.linkedId);
       if (board === undefined) {
         return null;
       } else {
@@ -1346,7 +1346,7 @@ Cards.helpers({
         return card.isOvertime;
       }
     } else if (this.isLinkedBoard()) {
-      const board = Boards.findOne({ _id: this.linkedId });
+      const board = ReactiveCache.getBoard(this.linkedId);
       if (board === undefined) {
         return null;
       } else {
@@ -1374,7 +1374,7 @@ Cards.helpers({
         return card.spentTime;
       }
     } else if (this.isLinkedBoard()) {
-      const board = Boards.findOne({ _id: this.linkedId });
+      const board = ReactiveCache.getBoard(this.linkedId);
       if (board === undefined) {
         return null;
       } else {
@@ -1404,7 +1404,7 @@ Cards.helpers({
         return null;
       }
     } else if (this.isLinkedBoard()) {
-      const board = Boards.findOne({ _id: this.linkedId });
+      const board = ReactiveCache.getBoard(this.linkedId);
       if (board === undefined) {
         return null;
       } else if (board && board.vote) {
@@ -1430,7 +1430,7 @@ Cards.helpers({
         return null;
       }
     } else if (this.isLinkedBoard()) {
-      const board = Boards.findOne({ _id: this.linkedId });
+      const board = ReactiveCache.getBoard(this.linkedId);
       if (board === undefined) {
         return null;
       } else if (board && board.vote) {
@@ -1456,7 +1456,7 @@ Cards.helpers({
         return null;
       }
     } else if (this.isLinkedBoard()) {
-      const board = Boards.findOne({ _id: this.linkedId });
+      const board = ReactiveCache.getBoard(this.linkedId);
       if (board === undefined) {
         return null;
       } else if (board && board.vote) {
@@ -1516,7 +1516,7 @@ Cards.helpers({
         return null;
       }
     } else if (this.isLinkedBoard()) {
-      const board = Boards.findOne({ _id: this.linkedId });
+      const board = ReactiveCache.getBoard(this.linkedId);
       if (board === undefined) {
         return null;
       } else if (board && board.poker) {
@@ -1550,7 +1550,7 @@ Cards.helpers({
         return null;
       }
     } else if (this.isLinkedBoard()) {
-      const board = Boards.findOne({ _id: this.linkedId });
+      const board = ReactiveCache.getBoard(this.linkedId);
       if (board === undefined) {
         return null;
       } else if (board && board.poker) {
@@ -1699,7 +1699,7 @@ Cards.helpers({
         return card.title;
       }
     } else if (this.isLinkedBoard()) {
-      const board = Boards.findOne({ _id: this.linkedId });
+      const board = ReactiveCache.getBoard(this.linkedId);
       if (board === undefined) {
         return null;
       } else {
@@ -1722,21 +1722,21 @@ Cards.helpers({
       if (card === undefined) {
         return null;
       }
-      const board = Boards.findOne({ _id: card.boardId });
+      const board = ReactiveCache.getBoard(card.boardId);
       if (board === undefined) {
         return null;
       } else {
         return board.title;
       }
     } else if (this.isLinkedBoard()) {
-      const board = Boards.findOne({ _id: this.linkedId });
+      const board = ReactiveCache.getBoard(this.linkedId);
       if (board === undefined) {
         return null;
       } else {
         return board.title;
       }
     } else {
-      const board = Boards.findOne({ _id: this.boardId });
+      const board = ReactiveCache.getBoard(this.boardId);
       if (board === undefined) {
         return null;
       } else {
@@ -1762,7 +1762,7 @@ Cards.helpers({
         return card.archived;
       }
     } else if (this.isLinkedBoard()) {
-      const board = Boards.findOne({ _id: this.linkedId });
+      const board = ReactiveCache.getBoard(this.linkedId);
       if (board === undefined) {
         return null;
       } else {
@@ -1967,7 +1967,7 @@ Cards.mutations({
     // This should never happen, but there was a bug that was fixed in commit
     // ea0239538a68e225c867411a4f3e0d27c158383.
     if (!swimlaneId) {
-      const board = Boards.findOne(boardId);
+      const board = ReactiveCache.getBoard(boardId);
       swimlaneId = board.getDefaultSwimline()._id;
     }
     // Move the minicard to the end of the target list
@@ -1993,7 +1993,7 @@ Cards.mutations({
     // This should never happen, but there was a bug that was fixed in commit
     // ea0239538a68e225c867411a4f3e0d27c158383.
     if (!swimlaneId) {
-      const board = Boards.findOne(boardId);
+      const board = ReactiveCache.getBoard(boardId);
       swimlaneId = board.getDefaultSwimline()._id;
     }
     listId = listId || this.listId;
@@ -2016,7 +2016,7 @@ Cards.mutations({
     // differs from the source board
     if (this.boardId !== boardId) {
       // Get label names
-      const oldBoard = Boards.findOne(this.boardId);
+      const oldBoard = ReactiveCache.getBoard(this.boardId);
       const oldBoardLabels = oldBoard.labels;
       const oldCardLabels = _.pluck(
         _.filter(oldBoardLabels, label => {
@@ -2025,7 +2025,7 @@ Cards.mutations({
         'name',
       );
 
-      const newBoard = Boards.findOne(boardId);
+      const newBoard = ReactiveCache.getBoard(boardId);
       const newBoardLabels = newBoard.labels;
       const newCardLabelIds = _.pluck(
         _.filter(newBoardLabels, label => {
@@ -2683,10 +2683,10 @@ function cardMove(
     Activities.insert({
       userId,
       activityType: 'moveCardBoard',
-      boardName: Boards.findOne(doc.boardId).title,
+      boardName: ReactiveCache.getBoard(doc.boardId).title,
       boardId: doc.boardId,
       oldBoardId,
-      oldBoardName: Boards.findOne(oldBoardId).title,
+      oldBoardName: ReactiveCache.getBoard(oldBoardId).title,
       cardId: doc._id,
       swimlaneName: Swimlanes.findOne(doc.swimlaneId).title,
       swimlaneId: doc.swimlaneId,
@@ -3320,9 +3320,7 @@ if (Meteor.isServer) {
     Authentication.checkLoggedIn(req.userId);
     const paramBoardId = req.params.boardId;
     // Check user has permission to add card to the board
-    const board = Boards.findOne({
-      _id: paramBoardId,
-    });
+    const board = ReactiveCache.getBoard(paramBoardId);
     const addPermission = allowIsBoardMemberCommentOnly(req.userId, board);
     Authentication.checkAdminOrCondition(req.userId, addPermission);
     const paramListId = req.params.listId;

+ 2 - 3
models/checklists.js

@@ -1,3 +1,4 @@
+import { ReactiveCache } from '/imports/reactiveCache';
 import { DataCache } from 'meteor-reactive-cache'
 
 Checklists = new Mongo.Collection('checklists');
@@ -350,9 +351,7 @@ if (Meteor.isServer) {
       const paramBoardId = req.params.boardId;
       Authentication.checkBoardAccess(req.userId, paramBoardId);
       // Check user has permission to add checklist to the card
-      const board = Boards.findOne({
-        _id: paramBoardId,
-      });
+      const board = ReactiveCache.getBoard(paramBoardId);
       const addPermission = allowIsBoardMemberCommentOnly(req.userId, board);
       Authentication.checkAdminOrCondition(req.userId, addPermission);
       const paramCardId = req.params.cardId;

+ 3 - 2
models/csvCreator.js

@@ -1,3 +1,4 @@
+import { ReactiveCache } from '/imports/reactiveCache';
 import { isEmptyObject } from 'jquery';
 import Boards from './boards';
 
@@ -320,7 +321,7 @@ export class CsvCreator {
       }
       // add the labels
       if (csvData[i][this.fieldIndex.labels]) {
-        const board = Boards.findOne(boardId);
+        const board = ReactiveCache.getBoard(boardId);
         for (const importedLabel of csvData[i][this.fieldIndex.labels].split(
           ' ',
         )) {
@@ -387,7 +388,7 @@ export class CsvCreator {
       Meteor.settings.public &&
       Meteor.settings.public.sandstorm;
     if (isSandstorm && currentBoardId) {
-      const currentBoard = Boards.findOne(currentBoardId);
+      const currentBoard = ReactiveCache.getBoard(currentBoardId);
       currentBoard.archive();
     }
     this.mapHeadertoCardFieldIndex(board[0]);

+ 3 - 1
models/customFields.js

@@ -1,3 +1,5 @@
+import { ReactiveCache } from '/imports/reactiveCache';
+
 CustomFields = new Mongo.Collection('customFields');
 
 /**
@@ -363,7 +365,7 @@ if (Meteor.isServer) {
   ) {
     const paramBoardId = req.params.boardId;
     Authentication.checkBoardAccess(req.userId, paramBoardId);
-    const board = Boards.findOne({ _id: paramBoardId });
+    const board = ReactiveCache.getBoard(paramBoardId);
     const id = CustomFields.direct.insert({
       name: req.body.name,
       type: req.body.type,

+ 3 - 2
models/exporter.js

@@ -1,3 +1,4 @@
+import { ReactiveCache } from '/imports/reactiveCache';
 import moment from 'moment/min/moment-with-locales';
 const Papa = require('papaparse');
 import { TAPi18n } from '/imports/i18n';
@@ -34,7 +35,7 @@ export class Exporter {
     };
     _.extend(
       result,
-      Boards.findOne(this._boardId, {
+      ReactiveCache.getBoard(this._boardId, {
         fields: {
           stars: 0,
         },
@@ -379,7 +380,7 @@ export class Exporter {
   }
 
   canExport(user) {
-    const board = Boards.findOne(this._boardId);
+    const board = ReactiveCache.getBoard(this._boardId);
     return board && board.isVisibleBy(user);
   }
 }

+ 3 - 1
models/integrations.js

@@ -1,3 +1,5 @@
+import { ReactiveCache } from '/imports/reactiveCache';
+
 Integrations = new Mongo.Collection('integrations');
 
 /**
@@ -102,7 +104,7 @@ const permissionHelper = {
   allow(userId, doc) {
     const user = Users.findOne(userId);
     const isAdmin = user && Meteor.user().isAdmin;
-    return isAdmin || allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
+    return isAdmin || allowIsBoardAdmin(userId, ReactiveCache.getBoard(doc.boardId));
   },
 };
 Integrations.allow({

+ 6 - 5
models/lists.js

@@ -1,3 +1,4 @@
+import { ReactiveCache } from '/imports/reactiveCache';
 import { ALLOWED_COLORS } from '/config/const';
 
 Lists = new Mongo.Collection('lists');
@@ -175,13 +176,13 @@ Lists.attachSchema(
 
 Lists.allow({
   insert(userId, doc) {
-    return allowIsBoardMemberCommentOnly(userId, Boards.findOne(doc.boardId));
+    return allowIsBoardMemberCommentOnly(userId, ReactiveCache.getBoard(doc.boardId));
   },
   update(userId, doc) {
-    return allowIsBoardMemberCommentOnly(userId, Boards.findOne(doc.boardId));
+    return allowIsBoardMemberCommentOnly(userId, ReactiveCache.getBoard(doc.boardId));
   },
   remove(userId, doc) {
-    return allowIsBoardMemberCommentOnly(userId, Boards.findOne(doc.boardId));
+    return allowIsBoardMemberCommentOnly(userId, ReactiveCache.getBoard(doc.boardId));
   },
   fetch: ['boardId'],
 });
@@ -269,7 +270,7 @@ Lists.helpers({
   },
 
   board() {
-    return Boards.findOne(this.boardId);
+    return ReactiveCache.getBoard(this.boardId);
   },
 
   getWipLimit(option) {
@@ -559,7 +560,7 @@ if (Meteor.isServer) {
     try {
       const paramBoardId = req.params.boardId;
       Authentication.checkBoardAccess(req.userId, paramBoardId);
-      const board = Boards.findOne(paramBoardId);
+      const board = ReactiveCache.getBoard(paramBoardId);
       const id = Lists.insert({
         title: req.body.title,
         boardId: paramBoardId,

+ 5 - 4
models/rules.js

@@ -1,3 +1,4 @@
+import { ReactiveCache } from '/imports/reactiveCache';
 import { Meteor } from 'meteor/meteor';
 
 Rules = new Mongo.Collection('rules');
@@ -63,7 +64,7 @@ Rules.helpers({
     return Triggers.findOne({ _id: this.triggerId });
   },
   board() {
-    return Boards.findOne({ _id: this.boardId });
+    return ReactiveCache.getBoard(this.boardId);
   },
   trigger() {
     return Triggers.findOne({ _id: this.triggerId });
@@ -75,13 +76,13 @@ Rules.helpers({
 
 Rules.allow({
   insert(userId, doc) {
-    return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
+    return allowIsBoardAdmin(userId, ReactiveCache.getBoard(doc.boardId));
   },
   update(userId, doc) {
-    return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
+    return allowIsBoardAdmin(userId, ReactiveCache.getBoard(doc.boardId));
   },
   remove(userId, doc) {
-    return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
+    return allowIsBoardAdmin(userId, ReactiveCache.getBoard(doc.boardId));
   },
 });
 

+ 7 - 6
models/swimlanes.js

@@ -1,3 +1,4 @@
+import { ReactiveCache } from '/imports/reactiveCache';
 import { ALLOWED_COLORS } from '/config/const';
 
 Swimlanes = new Mongo.Collection('swimlanes');
@@ -111,13 +112,13 @@ Swimlanes.attachSchema(
 
 Swimlanes.allow({
   insert(userId, doc) {
-    return allowIsBoardMemberCommentOnly(userId, Boards.findOne(doc.boardId));
+    return allowIsBoardMemberCommentOnly(userId, ReactiveCache.getBoard(doc.boardId));
   },
   update(userId, doc) {
-    return allowIsBoardMemberCommentOnly(userId, Boards.findOne(doc.boardId));
+    return allowIsBoardMemberCommentOnly(userId, ReactiveCache.getBoard(doc.boardId));
   },
   remove(userId, doc) {
-    return allowIsBoardMemberCommentOnly(userId, Boards.findOne(doc.boardId));
+    return allowIsBoardMemberCommentOnly(userId, ReactiveCache.getBoard(doc.boardId));
   },
   fetch: ['boardId'],
 });
@@ -235,7 +236,7 @@ Swimlanes.helpers({
   },
 
   board() {
-    return Boards.findOne(this.boardId);
+    return ReactiveCache.getBoard(this.boardId);
   },
 
   colorClass() {
@@ -469,7 +470,7 @@ if (Meteor.isServer) {
       const paramBoardId = req.params.boardId;
       Authentication.checkBoardAccess(req.userId, paramBoardId);
 
-      const board = Boards.findOne(paramBoardId);
+      const board = ReactiveCache.getBoard(paramBoardId);
       const id = Swimlanes.insert({
         title: req.body.title,
         boardId: paramBoardId,
@@ -504,7 +505,7 @@ if (Meteor.isServer) {
       const paramBoardId = req.params.boardId;
       const paramSwimlaneId = req.params.swimlaneId;
       Authentication.checkBoardAccess(req.userId, paramBoardId);
-      const board = Boards.findOne(paramBoardId);
+      const board = ReactiveCache.getBoard(paramBoardId);
       const swimlane = Swimlanes.findOne({
         _id: paramSwimlaneId,
         boardId: paramBoardId,

+ 2 - 1
models/trelloCreator.js

@@ -1,3 +1,4 @@
+import { ReactiveCache } from '/imports/reactiveCache';
 import moment from 'moment/min/moment-with-locales';
 import { TAPi18n } from '/imports/i18n';
 
@@ -753,7 +754,7 @@ export class TrelloCreator {
       Meteor.settings.public &&
       Meteor.settings.public.sandstorm;
     if (isSandstorm && currentBoardId) {
-      const currentBoard = Boards.findOne(currentBoardId);
+      const currentBoard = ReactiveCache.getBoard(currentBoardId);
       currentBoard.archive();
     }
     this.parseActions(board.actions);

+ 4 - 3
models/triggers.js

@@ -1,3 +1,4 @@
+import { ReactiveCache } from '/imports/reactiveCache';
 import { Meteor } from 'meteor/meteor';
 
 Triggers = new Mongo.Collection('triggers');
@@ -24,13 +25,13 @@ Triggers.before.update((userId, doc, fieldNames, modifier) => {
 
 Triggers.allow({
   insert(userId, doc) {
-    return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
+    return allowIsBoardAdmin(userId, ReactiveCache.getBoard(doc.boardId));
   },
   update(userId, doc) {
-    return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
+    return allowIsBoardAdmin(userId, ReactiveCache.getBoard(doc.boardId));
   },
   remove(userId, doc) {
-    return allowIsBoardAdmin(userId, Boards.findOne(doc.boardId));
+    return allowIsBoardAdmin(userId, ReactiveCache.getBoard(doc.boardId));
   },
 });
 

+ 4 - 4
models/users.js

@@ -621,7 +621,7 @@ if (Meteor.isClient) {
     isBoardAdmin(boardId) {
       let board;
       if (boardId) {
-        board = Boards.findOne(boardId);
+        board = ReactiveCache.getBoard(boardId);
       } else {
         board = Utils.getCurrentBoard();
       }
@@ -1388,7 +1388,7 @@ if (Meteor.isServer) {
       check(boardId, String);
 
       const inviter = Meteor.user();
-      const board = Boards.findOne(boardId);
+      const board = ReactiveCache.getBoard(boardId);
       const allowInvite =
         inviter &&
         board &&
@@ -1453,7 +1453,7 @@ if (Meteor.isServer) {
 
       //Check if there is a subtasks board
       if (board.subtasksDefaultBoardId) {
-        const subBoard = Boards.findOne(board.subtasksDefaultBoardId);
+        const subBoard = ReactiveCache.getBoard(board.subtasksDefaultBoardId);
         //If there is, also add user to that board
         if (subBoard) {
           subBoard.addMember(user._id);
@@ -1989,7 +1989,7 @@ if (Meteor.isServer) {
         throw new Meteor.Error('error-invitation-code-not-exist');
       } else {
         invitationCode.boardsToBeInvited.forEach((boardId) => {
-          const board = Boards.findOne(boardId);
+          const board = ReactiveCache.getBoard(boardId);
           board.addMember(doc._id);
         });
         if (!doc.profile) {

+ 2 - 1
models/wekanCreator.js

@@ -1,3 +1,4 @@
+import { ReactiveCache } from '/imports/reactiveCache';
 import moment from 'moment/min/moment-with-locales';
 
 const DateString = Match.Where(function(dateAsString) {
@@ -907,7 +908,7 @@ export class WekanCreator {
       Meteor.settings.public &&
       Meteor.settings.public.sandstorm;
     if (isSandstorm && currentBoardId) {
-      const currentBoard = Boards.findOne(currentBoardId);
+      const currentBoard = ReactiveCache.getBoard(currentBoardId);
       currentBoard.archive();
     }
     this.parseActivities(board);

+ 2 - 1
sandstorm.js

@@ -1,3 +1,4 @@
+import { ReactiveCache } from '/imports/reactiveCache';
 import { Meteor } from 'meteor/meteor';
 import { Picker } from 'meteor/communitypackages:picker';
 
@@ -215,7 +216,7 @@ if (isSandstorm && Meteor.isServer) {
             const comment = CardComments.findOne(doc.commentId);
             caption = { defaultText: comment.text };
             const activeMembers = _.pluck(
-              Boards.findOne(sandstormBoard._id).activeMembers(),
+              ReactiveCache.getBoard(sandstormBoard._id).activeMembers(),
               'userId',
             );
             (comment.text.match(/\B@([\w.]*)/g) || []).forEach(username => {

+ 2 - 1
server/authentication.js

@@ -1,3 +1,4 @@
+import { ReactiveCache } from '/imports/reactiveCache';
 import Fiber from 'fibers';
 
 Meteor.startup(() => {
@@ -55,7 +56,7 @@ Meteor.startup(() => {
   Authentication.checkBoardAccess = function(userId, boardId) {
     Authentication.checkLoggedIn(userId);
 
-    const board = Boards.findOne({ _id: boardId });
+    const board = ReactiveCache.getBoard(boardId);
     const normalAccess =
       board.permission === 'public' ||
       board.members.some(e => e.userId === userId && e.isActive);

+ 2 - 1
server/notifications/outgoing.js

@@ -1,3 +1,4 @@
+import { ReactiveCache } from '/imports/reactiveCache';
 import { TAPi18n } from '/imports/i18n';
 
 if (Meteor.isServer) {
@@ -79,7 +80,7 @@ if (Meteor.isServer) {
         cardId: paramCardId,
         boardId: paramBoardId,
       });
-      const board = Boards.findOne(paramBoardId);
+      const board = ReactiveCache.getBoard(paramBoardId);
       const card = Cards.findOne(paramCardId);
       if (board && card) {
         if (comment) {

+ 3 - 1
server/notifications/watch.js

@@ -1,3 +1,5 @@
+import { ReactiveCache } from '/imports/reactiveCache';
+
 Meteor.methods({
   watch(watchableType, id, level) {
     check(watchableType, String);
@@ -9,7 +11,7 @@ Meteor.methods({
     let watchableObj = null;
     let board = null;
     if (watchableType === 'board') {
-      watchableObj = Boards.findOne(id);
+      watchableObj = ReactiveCache.getBoard(id);
       if (!watchableObj) throw new Meteor.Error('error-board-doesNotExist');
       board = watchableObj;
     } else if (watchableType === 'list') {

+ 2 - 1
server/publications/boards.js

@@ -2,6 +2,7 @@
 // non-archived boards:
 // 1. that the user is a member of
 // 2. the user has starred
+import { ReactiveCache } from '/imports/reactiveCache';
 import Users from "../../models/users";
 import Org from "../../models/org";
 import Team from "../../models/team";
@@ -326,7 +327,7 @@ Meteor.methods({
     check(boardId, String);
     check(properties, Object);
 
-    const board = Boards.findOne(boardId);
+    const board = ReactiveCache.getBoard(boardId);
     if (board) {
       for (const key in properties) {
         board[key] = properties[key];

+ 4 - 2
server/publications/swimlanes.js

@@ -1,10 +1,12 @@
+import { ReactiveCache } from '/imports/reactiveCache';
+
 Meteor.methods({
   copySwimlane(swimlaneId, toBoardId) {
     check(swimlaneId, String);
     check(toBoardId, String);
 
     const swimlane = Swimlanes.findOne(swimlaneId);
-    const toBoard = Boards.findOne(toBoardId);
+    const toBoard = ReactiveCache.getBoard(toBoardId);
 
     if (swimlane && toBoard) {
       swimlane.copy(toBoardId);
@@ -19,7 +21,7 @@ Meteor.methods({
     check(toBoardId, String);
 
     const swimlane = Swimlanes.findOne(swimlaneId);
-    const toBoard = Boards.findOne(toBoardId);
+    const toBoard = ReactiveCache.getBoard(toBoardId);
 
     if (swimlane && toBoard) {
       swimlane.move(toBoardId);