Explorar o código

Move every CardComments.findOne() to the ReactiveCache

Martin Filser %!s(int64=2) %!d(string=hai) anos
pai
achega
0a7ffe4cb0

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

@@ -286,7 +286,7 @@ Template.commentReactions.events({
     if (ReactiveCache.getCurrentUser().isBoardMember()) {
       const codepoint = event.currentTarget.dataset['codepoint'];
       const commentId = Template.instance().data.commentId;
-      const cardComment = CardComments.findOne({_id: commentId});
+      const cardComment = ReactiveCache.getCardComment(commentId);
       cardComment.toggleReaction(codepoint);
     }
   },
@@ -298,7 +298,7 @@ Template.addReactionPopup.events({
     if (ReactiveCache.getCurrentUser().isBoardMember()) {
       const codepoint = event.currentTarget.dataset['codepoint'];
       const commentId = Template.instance().data.commentId;
-      const cardComment = CardComments.findOne({_id: commentId});
+      const cardComment = ReactiveCache.getCardComment(commentId);
       cardComment.toggleReaction(codepoint);
     }
     Popup.back();

+ 23 - 0
imports/reactiveCache.js

@@ -27,6 +27,10 @@ ReactiveCacheServer = {
     const ret = Cards.findOne(id);
     return ret;
   },
+  getCardComment(id) {
+    const ret = CardComments.findOne(id);
+    return ret;
+  },
   getCustomField(id) {
     const ret = CustomFields.findOne(id);
     return ret;
@@ -113,6 +117,16 @@ ReactiveCacheClient = {
     const ret = this.__card.get(id);
     return ret;
   },
+  getCardComment(id) {
+    if (!this.__cardComment) {
+      this.__cardComment = new DataCache(_id => {
+        const _ret = CardComments.findOne(_id);
+        return _ret;
+      });
+    }
+    const ret = this.__cardComment.get(id);
+    return ret;
+  },
   getCustomField(id) {
     if (!this.__customField) {
       this.__customField = new DataCache(customFieldId => {
@@ -226,6 +240,15 @@ ReactiveCache = {
     }
     return ret;
   },
+  getCardComment(id) {
+    let ret;
+    if (Meteor.isServer) {
+      ret = ReactiveCacheServer.getCardComment(id);
+    } else {
+      ret = ReactiveCacheClient.getCardComment(id);
+    }
+    return ret;
+  },
   getCustomField(id) {
     let ret;
     if (Meteor.isServer) {

+ 1 - 1
models/activities.js

@@ -41,7 +41,7 @@ Activities.helpers({
     return ReactiveCache.getCard(this.cardId);
   },
   comment() {
-    return CardComments.findOne(this.commentId);
+    return ReactiveCache.getCardComment(this.commentId);
   },
   attachment() {
     return Attachments.findOne(this.attachmentId);

+ 1 - 1
sandstorm.js

@@ -213,7 +213,7 @@ if (isSandstorm && Meteor.isServer) {
           }
 
           if (doc.activityType === 'addComment') {
-            const comment = CardComments.findOne(doc.commentId);
+            const comment = ReactiveCache.getCardComment(doc.commentId);
             caption = { defaultText: comment.text };
             const activeMembers = _.pluck(
               ReactiveCache.getBoard(sandstormBoard._id).activeMembers(),