Browse Source

Move every Cards.findOne() to the ReactiveCache

Martin Filser 2 years ago
parent
commit
3b65113d05

+ 3 - 1
client/components/activities/comments.js

@@ -1,3 +1,5 @@
+import { ReactiveCache } from '/imports/reactiveCache';
+
 const commentFormIsOpen = new ReactiveVar(false);
 
 BlazeComponent.extendComponent({
@@ -24,7 +26,7 @@ BlazeComponent.extendComponent({
           let boardId = card.boardId;
           let cardId = card._id;
           if (card.isLinkedCard()) {
-            boardId = Cards.findOne(card.linkedId).boardId;
+            boardId = ReactiveCache.getCard(card.linkedId).boardId;
             cardId = card.linkedId;
           } else if (card.isLinkedBoard()) {
             boardId = card.linkedId;

+ 3 - 2
client/components/boards/boardBody.js

@@ -1,3 +1,4 @@
+import { ReactiveCache } from '/imports/reactiveCache';
 import { TAPi18n } from '/imports/i18n';
 
 const subManager = new SubsManager();
@@ -388,7 +389,7 @@ BlazeComponent.extendComponent({
       },
       eventResize(event, delta, revertFunc) {
         let isOk = false;
-        const card = Cards.findOne(event.id);
+        const card = ReactiveCache.getCard(event.id);
 
         if (card) {
           card.setEnd(event.end.toDate());
@@ -400,7 +401,7 @@ BlazeComponent.extendComponent({
       },
       eventDrop(event, delta, revertFunc) {
         let isOk = false;
-        const card = Cards.findOne(event.id);
+        const card = ReactiveCache.getCard(event.id);
         if (card) {
           // TODO: add a flag for allDay events
           if (!event.allDay) {

+ 4 - 3
client/components/cards/attachments.js

@@ -1,3 +1,4 @@
+import { ReactiveCache } from '/imports/reactiveCache';
 import { ObjectID } from 'bson';
 import DOMPurify from 'dompurify';
 
@@ -322,7 +323,7 @@ Template.previewClipboardImagePopup.events({
 
 BlazeComponent.extendComponent({
   isCover() {
-    const ret = Cards.findOne(this.data().meta.cardId).coverId == this.data()._id;
+    const ret = ReactiveCache.getCard(this.data().meta.cardId).coverId == this.data()._id;
     return ret;
   },
   isBackgroundImage() {
@@ -334,11 +335,11 @@ BlazeComponent.extendComponent({
     return [
       {
         'click .js-add-cover'() {
-          Cards.findOne(this.data().meta.cardId).setCover(this.data()._id);
+          ReactiveCache.getCard(this.data().meta.cardId).setCover(this.data()._id);
           Popup.back();
         },
         'click .js-remove-cover'() {
-          Cards.findOne(this.data().meta.cardId).unsetCover();
+          ReactiveCache.getCard(this.data().meta.cardId).unsetCover();
           Popup.back();
         },
         'click .js-add-background-image'() {

+ 3 - 3
client/components/cards/cardDetails.js

@@ -873,7 +873,7 @@ Template.editCardAssignerForm.events({
         swimlaneId: swimlaneId,
         sort: 0,
       });
-      const card = Cards.findOne(_id);
+      const card = ReactiveCache.getCard(_id);
       const minOrder = card.getMinSort();
       card.move(card.boardId, card.swimlaneId, card.listId, minOrder - 1);
 
@@ -1005,7 +1005,7 @@ BlazeComponent.extendComponent({
 
   setParentCardId(cardId) {
     if (cardId) {
-      this.parentCard = Cards.findOne(cardId);
+      this.parentCard = ReactiveCache.getCard(cardId);
     } else {
       this.parentCard = null;
     }
@@ -1684,7 +1684,7 @@ Template.cardAssigneePopup.helpers({
 
 Template.cardAssigneePopup.events({
   'click .js-remove-assignee'() {
-    Cards.findOne(this.cardId).unassignAssignee(this.userId);
+    ReactiveCache.getCard(this.cardId).unassignAssignee(this.userId);
     Popup.back();
   },
   'click .js-edit-profile': Popup.open('editProfile'),

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

@@ -85,9 +85,11 @@ BlazeComponent.extendComponent({
     const textarea = this.find('textarea.js-add-checklist-item');
     const title = textarea.value.trim();
     let cardId = this.currentData().cardId;
-    const card = Cards.findOne(cardId);
+    const card = ReactiveCache.getCard(cardId);
     //if (card.isLinked()) cardId = card.linkedId;
-    if (card.isLinkedCard()) cardId = card.linkedId;
+    if (card.isLinkedCard()) {
+      cardId = card.linkedId;
+    }
 
     let sortIndex;
     let checklistItemIndex;
@@ -267,7 +269,7 @@ BlazeComponent.extendComponent({
 
 Template.checklists.helpers({
   checklists() {
-    const card = Cards.findOne(this.cardId);
+    const card = ReactiveCache.getCard(this.cardId);
     const ret = card.checklists();
     return ret;
   },

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

@@ -1,3 +1,5 @@
+import { ReactiveCache } from '/imports/reactiveCache';
+
 let labelColors;
 Meteor.startup(() => {
   labelColors = Boards.simpleSchema()._schema['labels.$.color'].allowedValues;
@@ -149,6 +151,6 @@ Template.editLabelPopup.events({
 
 Template.cardLabelsPopup.helpers({
   isLabelSelected(cardId) {
-    return _.contains(Cards.findOne(cardId).labelIds, this._id);
+    return _.contains(ReactiveCache.getCard(cardId).labelIds, this._id);
   },
 });

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

@@ -6,7 +6,7 @@ BlazeComponent.extendComponent({
     const textarea = this.find('textarea.js-add-subtask-item');
     const title = textarea.value.trim();
     const cardId = this.currentData().cardId;
-    const card = Cards.findOne(cardId);
+    const card = ReactiveCache.getCard(cardId);
     const sortIndex = -1;
     const crtBoard = ReactiveCache.getBoard(card.boardId);
     const targetBoard = crtBoard.getDefaultSubtasksBoard();

+ 2 - 1
client/components/lists/list.js

@@ -1,3 +1,4 @@
+import { ReactiveCache } from '/imports/reactiveCache';
 import { TAPi18n } from '/imports/i18n';
 require('/client/lib/jquery-ui.js')
 
@@ -188,7 +189,7 @@ BlazeComponent.extendComponent({
           accept: '.js-member,.js-label',
           drop(event, ui) {
             const cardId = Blaze.getData(this)._id;
-            const card = Cards.findOne(cardId);
+            const card = ReactiveCache.getCard(cardId);
 
             if (ui.draggable.hasClass('js-member')) {
               const memberId = Blaze.getData(ui.draggable.get(0)).userId;

+ 2 - 1
client/components/users/userAvatar.js

@@ -1,3 +1,4 @@
+import { ReactiveCache } from '/imports/reactiveCache';
 import Cards from '/models/cards';
 import Avatars from '/models/avatars';
 import Users from '/models/users';
@@ -269,7 +270,7 @@ Template.cardMemberPopup.helpers({
 
 Template.cardMemberPopup.events({
   'click .js-remove-member'() {
-    Cards.findOne(this.cardId).unassignMember(this.userId);
+    ReactiveCache.getCard(this.cardId).unassignMember(this.userId);
     Popup.back();
   },
   'click .js-edit-profile': Popup.open('editProfile'),

+ 2 - 1
client/lib/cardSearch.js

@@ -1,3 +1,4 @@
+import { ReactiveCache } from '/imports/reactiveCache';
 import { TAPi18n } from '/imports/i18n';
 import Cards from '../../models/cards';
 import SessionData from '../../models/usersessiondata';
@@ -74,7 +75,7 @@ export class CardSearchPagedComponent extends BlazeComponent {
     console.log('session data:', this.sessionData);
     const cards = [];
     this.sessionData.cards.forEach(cardId => {
-      cards.push(Cards.findOne({ _id: cardId }));
+      cards.push(ReactiveCache.getCard(cardId));
     });
     this.queryErrors = this.sessionData.errors;
     if (this.queryErrors.length) {

+ 5 - 5
client/lib/keyboard.js

@@ -85,7 +85,7 @@ Mousetrap.bind(numbArray, (evt, key) => {
     const cardIds = MultiSelection.getSelectedCardIds();
     for (const cardId of cardIds)
     {
-      card = Cards.findOne(cardId);
+      card = ReactiveCache.getCard(cardId);
       if(num <= board.labels.length)
       {
         card.removeLabel(labels[num-1]["_id"]);
@@ -109,7 +109,7 @@ Mousetrap.bind(numArray, (evt, key) => {
     const cardIds = MultiSelection.getSelectedCardIds();
     for (const cardId of cardIds)
     {
-      card = Cards.findOne(cardId);
+      card = ReactiveCache.getCard(cardId);
       if(num <= board.labels.length)
       {
         card.addLabel(labels[num-1]["_id"]);
@@ -123,7 +123,7 @@ Mousetrap.bind(numArray, (evt, key) => {
     return;
   }
   if (Meteor.user().isBoardMember()) {
-    const card = Cards.findOne(cardId);
+    const card = ReactiveCache.getCard(cardId);
     if(num <= board.labels.length)
     {
       card.toggleLabel(labels[num-1]["_id"]);
@@ -143,7 +143,7 @@ Mousetrap.bind('space', evt => {
   }
 
   if (Meteor.user().isBoardMember()) {
-    const card = Cards.findOne(cardId);
+    const card = ReactiveCache.getCard(cardId);
     card.toggleMember(currentUserId);
     // We should prevent scrolling in card when spacebar is clicked
     // This should do it according to Mousetrap docs, but it doesn't
@@ -167,7 +167,7 @@ Mousetrap.bind('c', evt => {
     !Meteor.user().isCommentOnly() &&
     !Meteor.user().isWorker()
   ) {
-    const card = Cards.findOne(cardId);
+    const card = ReactiveCache.getCard(cardId);
     card.archive();
     // We should prevent scrolling in card when spacebar is clicked
     // This should do it according to Mousetrap docs, but it doesn't

+ 3 - 1
client/lib/multiSelection.js

@@ -1,3 +1,5 @@
+import { ReactiveCache } from '/imports/reactiveCache';
+
 function getCardsBetween(idA, idB) {
   function pluckId(doc) {
     return doc._id;
@@ -13,7 +15,7 @@ function getCardsBetween(idA, idB) {
     }).map(pluckId);
   }
 
-  const cards = _.sortBy([Cards.findOne(idA), Cards.findOne(idB)], c => {
+  const cards = _.sortBy([ReactiveCache.getCard(idA), ReactiveCache.getCard(idB)], c => {
     return c.sort;
   });
 

+ 2 - 2
client/lib/utils.js

@@ -212,7 +212,7 @@ Utils = {
   },
 
   goCardId(_id) {
-    const card = Cards.findOne(_id);
+    const card = ReactiveCache.getCard(_id);
     const board = ReactiveCache.getBoard(card.boardId);
     return (
       board &&
@@ -226,7 +226,7 @@ Utils = {
   getCommonAttachmentMetaFrom(card) {
     const meta = {};
     if (card.isLinkedCard()) {
-      meta.boardId = Cards.findOne(card.linkedId).boardId;
+      meta.boardId = ReactiveCache.getCard(card.linkedId).boardId;
       meta.cardId = card.linkedId;
     } else {
       meta.boardId = card.boardId;

+ 3 - 3
models/activities.js

@@ -38,7 +38,7 @@ Activities.helpers({
     return Lists.findOne(this.oldListId);
   },
   card() {
-    return Cards.findOne(this.cardId);
+    return ReactiveCache.getCard(this.cardId);
   },
   comment() {
     return CardComments.findOne(this.commentId);
@@ -53,14 +53,14 @@ Activities.helpers({
     return ChecklistItems.findOne(this.checklistItemId);
   },
   subtasks() {
-    return Cards.findOne(this.subtaskId);
+    return ReactiveCache.getCard(this.subtaskId);
   },
   customField() {
     return CustomFields.findOne(this.customFieldId);
   },
   // Label activity did not work yet, unable to edit labels when tried this.
   //label() {
-  //  return Cards.findOne(this.labelId);
+  //  return ReactiveCache.getCard(this.labelId);
   //},
 });
 

+ 3 - 3
models/cardComments.js

@@ -147,7 +147,7 @@ CardComments.helpers({
 CardComments.hookOptions.after.update = { fetchPrevious: false };
 
 function commentCreation(userId, doc) {
-  const card = Cards.findOne(doc.cardId);
+  const card = ReactiveCache.getCard(doc.cardId);
   Activities.insert({
     userId,
     activityType: 'addComment',
@@ -194,7 +194,7 @@ if (Meteor.isServer) {
   });
 
   CardComments.after.update((userId, doc) => {
-    const card = Cards.findOne(doc.cardId);
+    const card = ReactiveCache.getCard(doc.cardId);
     Activities.insert({
       userId,
       activityType: 'editComment',
@@ -207,7 +207,7 @@ if (Meteor.isServer) {
   });
 
   CardComments.before.remove((userId, doc) => {
-    const card = Cards.findOne(doc.cardId);
+    const card = ReactiveCache.getCard(doc.cardId);
     Activities.insert({
       userId,
       activityType: 'deleteComment',

+ 28 - 34
models/cards.js

@@ -549,7 +549,7 @@ Cards.helpers({
 
   copy(boardId, swimlaneId, listId) {
     const oldId = this._id;
-    const oldCard = Cards.findOne(oldId);
+    const oldCard = ReactiveCache.getCard(oldId);
 
     // we must only copy the labels and custom fields if the target board
     // differs from the source board
@@ -1001,7 +1001,7 @@ Cards.helpers({
     if (this.parentId === '') {
       return null;
     }
-    return Cards.findOne(this.parentId);
+    return ReactiveCache.getCard(this.parentId);
   },
 
   parentCardName() {
@@ -1019,7 +1019,7 @@ Cards.helpers({
     const result = [];
     let crtParentId = this.parentId;
     while (crtParentId !== '') {
-      const crt = Cards.findOne(crtParentId);
+      const crt = ReactiveCache.getCard(crtParentId);
       if (crt === null || crt === undefined) {
         // maybe it has been deleted
         break;
@@ -1039,7 +1039,7 @@ Cards.helpers({
     const result = [];
     let crtParentId = this.parentId;
     while (crtParentId !== '') {
-      const crt = Cards.findOne(crtParentId);
+      const crt = ReactiveCache.getCard(crtParentId);
       if (crt === null || crt === undefined) {
         // maybe it has been deleted
         break;
@@ -1089,7 +1089,7 @@ Cards.helpers({
 
   getDescription() {
     if (this.isLinkedCard()) {
-      const card = Cards.findOne({ _id: this.linkedId });
+      const card = ReactiveCache.getCard(this.linkedId);
       if (card && card.description) return card.description;
       else return null;
     } else if (this.isLinkedBoard()) {
@@ -1105,7 +1105,7 @@ Cards.helpers({
 
   getMembers() {
     if (this.isLinkedCard()) {
-      const card = Cards.findOne({ _id: this.linkedId });
+      const card = ReactiveCache.getCard(this.linkedId);
       if (card === undefined) {
         return null;
       } else {
@@ -1127,7 +1127,7 @@ Cards.helpers({
 
   getAssignees() {
     if (this.isLinkedCard()) {
-      const card = Cards.findOne({ _id: this.linkedId });
+      const card = ReactiveCache.getCard(this.linkedId);
       if (card === undefined) {
         return null;
       } else {
@@ -1227,7 +1227,7 @@ Cards.helpers({
 
   getReceived() {
     if (this.isLinkedCard()) {
-      const card = Cards.findOne({ _id: this.linkedId });
+      const card = ReactiveCache.getCard(this.linkedId);
       if (card === undefined) {
         return null;
       } else {
@@ -1255,7 +1255,7 @@ Cards.helpers({
 
   getStart() {
     if (this.isLinkedCard()) {
-      const card = Cards.findOne({ _id: this.linkedId });
+      const card = ReactiveCache.getCard(this.linkedId);
       if (card === undefined) {
         return null;
       } else {
@@ -1283,7 +1283,7 @@ Cards.helpers({
 
   getDue() {
     if (this.isLinkedCard()) {
-      const card = Cards.findOne({ _id: this.linkedId });
+      const card = ReactiveCache.getCard(this.linkedId);
       if (card === undefined) {
         return null;
       } else {
@@ -1311,7 +1311,7 @@ Cards.helpers({
 
   getEnd() {
     if (this.isLinkedCard()) {
-      const card = Cards.findOne({ _id: this.linkedId });
+      const card = ReactiveCache.getCard(this.linkedId);
       if (card === undefined) {
         return null;
       } else {
@@ -1339,7 +1339,7 @@ Cards.helpers({
 
   getIsOvertime() {
     if (this.isLinkedCard()) {
-      const card = Cards.findOne({ _id: this.linkedId });
+      const card = ReactiveCache.getCard(this.linkedId);
       if (card === undefined) {
         return null;
       } else {
@@ -1367,7 +1367,7 @@ Cards.helpers({
 
   getSpentTime() {
     if (this.isLinkedCard()) {
-      const card = Cards.findOne({ _id: this.linkedId });
+      const card = ReactiveCache.getCard(this.linkedId);
       if (card === undefined) {
         return null;
       } else {
@@ -1395,7 +1395,7 @@ Cards.helpers({
 
   getVoteQuestion() {
     if (this.isLinkedCard()) {
-      const card = Cards.findOne({ _id: this.linkedId });
+      const card = ReactiveCache.getCard(this.linkedId);
       if (card === undefined) {
         return null;
       } else if (card && card.vote) {
@@ -1421,7 +1421,7 @@ Cards.helpers({
 
   getVotePublic() {
     if (this.isLinkedCard()) {
-      const card = Cards.findOne({ _id: this.linkedId });
+      const card = ReactiveCache.getCard(this.linkedId);
       if (card === undefined) {
         return null;
       } else if (card && card.vote) {
@@ -1447,7 +1447,7 @@ Cards.helpers({
 
   getVoteEnd() {
     if (this.isLinkedCard()) {
-      const card = Cards.findOne({ _id: this.linkedId });
+      const card = ReactiveCache.getCard(this.linkedId);
       if (card === undefined) {
         return null;
       } else if (card && card.vote) {
@@ -1507,7 +1507,7 @@ Cards.helpers({
 
   getPokerQuestion() {
     if (this.isLinkedCard()) {
-      const card = Cards.findOne({ _id: this.linkedId });
+      const card = ReactiveCache.getCard(this.linkedId);
       if (card === undefined) {
         return null;
       } else if (card && card.poker) {
@@ -1541,7 +1541,7 @@ Cards.helpers({
 
   getPokerEnd() {
     if (this.isLinkedCard()) {
-      const card = Cards.findOne({ _id: this.linkedId });
+      const card = ReactiveCache.getCard(this.linkedId);
       if (card === undefined) {
         return null;
       } else if (card && card.poker) {
@@ -1692,7 +1692,7 @@ Cards.helpers({
 
   getTitle() {
     if (this.isLinkedCard()) {
-      const card = Cards.findOne({ _id: this.linkedId });
+      const card = ReactiveCache.getCard(this.linkedId);
       if (card === undefined) {
         return null;
       } else {
@@ -1718,7 +1718,7 @@ Cards.helpers({
 
   getBoardTitle() {
     if (this.isLinkedCard()) {
-      const card = Cards.findOne({ _id: this.linkedId });
+      const card = ReactiveCache.getCard(this.linkedId);
       if (card === undefined) {
         return null;
       }
@@ -1755,7 +1755,7 @@ Cards.helpers({
 
   getArchived() {
     if (this.isLinkedCard()) {
-      const card = Cards.findOne({ _id: this.linkedId });
+      const card = ReactiveCache.getCard(this.linkedId);
       if (card === undefined) {
         return null;
       } else {
@@ -1779,7 +1779,7 @@ Cards.helpers({
 
   getRequestedBy() {
     if (this.isLinkedCard()) {
-      const card = Cards.findOne({ _id: this.linkedId });
+      const card = ReactiveCache.getCard(this.linkedId);
       if (card === undefined) {
         return null;
       } else {
@@ -1796,7 +1796,7 @@ Cards.helpers({
 
   getAssignedBy() {
     if (this.isLinkedCard()) {
-      const card = Cards.findOne({ _id: this.linkedId });
+      const card = ReactiveCache.getCard(this.linkedId);
       if (card === undefined) {
         return null;
       } else {
@@ -3057,7 +3057,7 @@ if (Meteor.isServer) {
       check(insertAtTop, Boolean);
       check(mergeCardValues, Object);
 
-      const card = Cards.findOne({_id: cardId});
+      const card = ReactiveCache.getCard(cardId);
       Object.assign(card, mergeCardValues);
 
       const sort = card.getSort(listId, swimlaneId, insertAtTop);
@@ -3140,7 +3140,7 @@ if (Meteor.isServer) {
       const value = modifier.$set[action];
       const oldvalue = doc[action] || '';
       const activityType = `a-${action}`;
-      const card = Cards.findOne(doc._id);
+      const card = ReactiveCache.getCard(doc._id);
       const list = card.list();
       if (list) {
         // change list modifiedAt, when user modified the key values in
@@ -3370,9 +3370,7 @@ if (Meteor.isServer) {
         },
       });
 
-      const card = Cards.findOne({
-        _id: id,
-      });
+      const card = ReactiveCache.getCard(id);
       cardCreation(req.body.authorId, card);
     } else {
       JsonRoutes.sendResult(res, {
@@ -3826,9 +3824,7 @@ JsonRoutes.add('GET', '/api/boards/:boardId/cards_count', function(
           },
         );
 
-        const card = Cards.findOne({
-          _id: paramCardId,
-        });
+        const card = ReactiveCache.getCard(paramCardId);
         cardMove(
           req.body.authorId,
           card,
@@ -3868,9 +3864,7 @@ JsonRoutes.add('GET', '/api/boards/:boardId/cards_count', function(
       const paramCardId = req.params.cardId;
       Authentication.checkBoardAccess(req.userId, paramBoardId);
 
-      const card = Cards.findOne({
-        _id: paramCardId,
-      });
+      const card = ReactiveCache.getCard(paramCardId);
       Cards.direct.remove({
         _id: paramCardId,
         listId: paramListId,

+ 10 - 8
models/checklistItems.js

@@ -1,3 +1,5 @@
+import { ReactiveCache } from '/imports/reactiveCache';
+
 ChecklistItems = new Mongo.Collection('checklistItems');
 
 /**
@@ -68,13 +70,13 @@ ChecklistItems.attachSchema(
 
 ChecklistItems.allow({
   insert(userId, doc) {
-    return allowIsBoardMemberByCard(userId, Cards.findOne(doc.cardId));
+    return allowIsBoardMemberByCard(userId, ReactiveCache.getCard(doc.cardId));
   },
   update(userId, doc) {
-    return allowIsBoardMemberByCard(userId, Cards.findOne(doc.cardId));
+    return allowIsBoardMemberByCard(userId, ReactiveCache.getCard(doc.cardId));
   },
   remove(userId, doc) {
-    return allowIsBoardMemberByCard(userId, Cards.findOne(doc.cardId));
+    return allowIsBoardMemberByCard(userId, ReactiveCache.getCard(doc.cardId));
   },
   fetch: ['userId', 'cardId'],
 });
@@ -113,7 +115,7 @@ ChecklistItems.mutations({
 
 // Activities helper
 function itemCreation(userId, doc) {
-  const card = Cards.findOne(doc.cardId);
+  const card = ReactiveCache.getCard(doc.cardId);
   const boardId = card.boardId;
   Activities.insert({
     userId,
@@ -135,7 +137,7 @@ function itemRemover(userId, doc) {
 }
 
 function publishCheckActivity(userId, doc) {
-  const card = Cards.findOne(doc.cardId);
+  const card = ReactiveCache.getCard(doc.cardId);
   const boardId = card.boardId;
   let activityType;
   if (doc.isFinished) {
@@ -158,7 +160,7 @@ function publishCheckActivity(userId, doc) {
 }
 
 function publishChekListCompleted(userId, doc) {
-  const card = Cards.findOne(doc.cardId);
+  const card = ReactiveCache.getCard(doc.cardId);
   const boardId = card.boardId;
   const checklistId = doc.checklistId;
   const checkList = Checklists.findOne({ _id: checklistId });
@@ -178,7 +180,7 @@ function publishChekListCompleted(userId, doc) {
 }
 
 function publishChekListUncompleted(userId, doc) {
-  const card = Cards.findOne(doc.cardId);
+  const card = ReactiveCache.getCard(doc.cardId);
   const boardId = card.boardId;
   const checklistId = doc.checklistId;
   const checkList = Checklists.findOne({ _id: checklistId });
@@ -233,7 +235,7 @@ if (Meteor.isServer) {
 
   ChecklistItems.before.remove((userId, doc) => {
     itemRemover(userId, doc);
-    const card = Cards.findOne(doc.cardId);
+    const card = ReactiveCache.getCard(doc.cardId);
     const boardId = card.boardId;
     Activities.insert({
       userId,

+ 6 - 6
models/checklists.js

@@ -148,13 +148,13 @@ Checklists.helpers({
 
 Checklists.allow({
   insert(userId, doc) {
-    return allowIsBoardMemberByCard(userId, Cards.findOne(doc.cardId));
+    return allowIsBoardMemberByCard(userId, ReactiveCache.getCard(doc.cardId));
   },
   update(userId, doc) {
-    return allowIsBoardMemberByCard(userId, Cards.findOne(doc.cardId));
+    return allowIsBoardMemberByCard(userId, ReactiveCache.getCard(doc.cardId));
   },
   remove(userId, doc) {
-    return allowIsBoardMemberByCard(userId, Cards.findOne(doc.cardId));
+    return allowIsBoardMemberByCard(userId, ReactiveCache.getCard(doc.cardId));
   },
   fetch: ['userId', 'cardId'],
 });
@@ -210,7 +210,7 @@ if (Meteor.isServer) {
   });
 
   Checklists.after.insert((userId, doc) => {
-    const card = Cards.findOne(doc.cardId);
+    const card = ReactiveCache.getCard(doc.cardId);
     Activities.insert({
       userId,
       activityType: 'addChecklist',
@@ -225,7 +225,7 @@ if (Meteor.isServer) {
 
   Checklists.before.remove((userId, doc) => {
     const activities = Activities.find({ checklistId: doc._id });
-    const card = Cards.findOne(doc.cardId);
+    const card = ReactiveCache.getCard(doc.cardId);
     if (activities) {
       activities.forEach(activity => {
         Activities.remove(activity._id);
@@ -235,7 +235,7 @@ if (Meteor.isServer) {
       userId,
       activityType: 'removeChecklist',
       cardId: doc.cardId,
-      boardId: Cards.findOne(doc.cardId).boardId,
+      boardId: ReactiveCache.getCard(doc.cardId).boardId,
       checklistId: doc._id,
       checklistName: doc.title,
       listId: card.listId,

+ 1 - 1
models/customFields.js

@@ -218,7 +218,7 @@ function customFieldDeletion(userId, doc) {
 // This has some bug, it does not show edited customField value at Outgoing Webhook,
 // instead it shows undefined, and no listId and swimlaneId.
 function customFieldEdit(userId, doc) {
-  const card = Cards.findOne(doc.cardId);
+  const card = ReactiveCache.getCard(doc.cardId);
   const customFieldValue = Activities.findOne({ customFieldId: doc._id }).value;
   Activities.insert({
     userId,

+ 1 - 1
models/wekanCreator.js

@@ -613,7 +613,7 @@ export class WekanCreator {
         : card.parentId;
 
       //if the parent card exists, proceed
-      if (Cards.findOne(parentIdInNewBoard)) {
+      if (ReactiveCache.getCard(parentIdInNewBoard)) {
         //set parent id of the card in the new board to the new id of the parent
         Cards.direct.update(cardIdInNewBoard, {
           $set: {

+ 1 - 1
sandstorm.js

@@ -205,7 +205,7 @@ if (isSandstorm && Meteor.isServer) {
 
           if (doc.cardId) {
             path = `b/sandstorm/libreboard/${doc.cardId}`;
-            Cards.findOne(doc.cardId).members.map(subscribedUser);
+            ReactiveCache.getCard(doc.cardId).members.map(subscribedUser);
           }
 
           if (doc.memberId) {

+ 1 - 1
server/notifications/outgoing.js

@@ -81,7 +81,7 @@ if (Meteor.isServer) {
         boardId: paramBoardId,
       });
       const board = ReactiveCache.getBoard(paramBoardId);
-      const card = Cards.findOne(paramCardId);
+      const card = ReactiveCache.getCard(paramCardId);
       if (board && card) {
         if (comment) {
           Lock.set(comment._id, newComment);

+ 1 - 1
server/notifications/watch.js

@@ -19,7 +19,7 @@ Meteor.methods({
       if (!watchableObj) throw new Meteor.Error('error-list-doesNotExist');
       board = watchableObj.board();
     } else if (watchableType === 'card') {
-      watchableObj = Cards.findOne(id);
+      watchableObj = ReactiveCache.getCard(id);
       if (!watchableObj) throw new Meteor.Error('error-card-doesNotExist');
       board = watchableObj.board();
     } else {

+ 3 - 3
server/rulesHelper.js

@@ -1,4 +1,4 @@
-//var nodemailer = require('nodemailer');
+import { ReactiveCache } from '/imports/reactiveCache';
 
 RulesHelper = {
   executeRules(activity) {
@@ -58,7 +58,7 @@ RulesHelper = {
     return matchingMap;
   },
   performAction(activity, action) {
-    const card = Cards.findOne({ _id: activity.cardId });
+    const card = ReactiveCache.getCard(activity.cardId);
     const boardId = activity.boardId;
     if (
       action.actionType === 'moveCardToTop' ||
@@ -376,7 +376,7 @@ RulesHelper = {
     }
     if (action.actionType === 'linkCard') {
       const list = Lists.findOne({ title: action.listName, boardId: action.boardId });
-      const card = Cards.findOne({ _id: activity.cardId });
+      const card = ReactiveCache.getCard(activity.cardId);
       let listId = '';
       let swimlaneId = '';
       const swimlane = Swimlanes.findOne({