瀏覽代碼

Move every CardCommentReactions.findOne(idOrFirstObjectSelector, options) to the ReactiveCache

Martin Filser 2 年之前
父節點
當前提交
e30edce73e
共有 2 個文件被更改,包括 52 次插入2 次删除
  1. 50 0
      imports/reactiveCache.js
  2. 2 2
      models/cardComments.js

+ 50 - 0
imports/reactiveCache.js

@@ -59,6 +59,14 @@ ReactiveCacheServer = {
     const ret = CardComments.find(selector, options).fetch();
     return ret;
   },
+  getCardCommentReaction(idOrFirstObjectSelector, options) {
+    const ret = CardCommentReactions.findOne(idOrFirstObjectSelector, options);
+    return ret;
+  },
+  getCardCommentReactions(selector, options) {
+    const ret = CardCommentReactions.find(selector, options).fetch();
+    return ret;
+  },
   getCustomField(idOrFirstObjectSelector, options) {
     const ret = CustomFields.findOne(idOrFirstObjectSelector, options);
     return ret;
@@ -313,6 +321,30 @@ ReactiveCacheClient = {
     const ret = this.__cardComments.get(Jsons.stringify(select));
     return ret;
   },
+  getCardCommentReaction(idOrFirstObjectSelector, options) {
+    const idOrFirstObjectSelect = {idOrFirstObjectSelector, options}
+    if (!this.__cardCommentReaction) {
+      this.__cardCommentReaction = new DataCache(_idOrFirstObjectSelect => {
+        const __select = Jsons.parse(_idOrFirstObjectSelect);
+        const _ret = CardCommentReactions.findOne(__select.idOrFirstObjectSelector, __select.options);
+        return _ret;
+      });
+    }
+    const ret = this.__cardCommentReaction.get(Jsons.stringify(idOrFirstObjectSelect));
+    return ret;
+  },
+  getCardCommentReactions(selector, options) {
+    const select = {selector, options}
+    if (!this.__cardCommentReactions) {
+      this.__cardCommentReactions = new DataCache(_select => {
+        const __select = Jsons.parse(_select);
+        const _ret = CardCommentReactions.find(__select.selector, __select.options).fetch();
+        return _ret;
+      });
+    }
+    const ret = this.__cardCommentReactions.get(Jsons.stringify(select));
+    return ret;
+  },
   getCustomField(idOrFirstObjectSelector, options) {
     const idOrFirstObjectSelect = {idOrFirstObjectSelector, options}
     if (!this.__customField) {
@@ -684,6 +716,24 @@ ReactiveCache = {
     }
     return ret;
   },
+  getCardCommentReaction(idOrFirstObjectSelector, options) {
+    let ret;
+    if (Meteor.isServer) {
+      ret = ReactiveCacheServer.getCardCommentReaction(idOrFirstObjectSelector, options);
+    } else {
+      ret = ReactiveCacheClient.getCardCommentReaction(idOrFirstObjectSelector, options);
+    }
+    return ret;
+  },
+  getCardCommentReactions(selector, options) {
+    let ret;
+    if (Meteor.isServer) {
+      ret = ReactiveCacheServer.getCardCommentReactions(selector, options);
+    } else {
+      ret = ReactiveCacheClient.getCardCommentReactions(selector, options);
+    }
+    return ret;
+  },
   getCustomField(idOrFirstObjectSelector, options) {
     let ret;
     if (Meteor.isServer) {

+ 2 - 2
models/cardComments.js

@@ -98,7 +98,7 @@ CardComments.helpers({
   },
 
   reactions() {
-    const cardCommentReactions = CardCommentReactions.findOne({cardCommentId: this._id});
+    const cardCommentReactions = ReactiveCache.getCardCommentReaction({cardCommentId: this._id});
     return !!cardCommentReactions ? cardCommentReactions.reactions : [];
   },
 
@@ -107,7 +107,7 @@ CardComments.helpers({
       return false;
     } else {
 
-      const cardCommentReactions = CardCommentReactions.findOne({cardCommentId: this._id});
+      const cardCommentReactions = ReactiveCache.getCardCommentReaction({cardCommentId: this._id});
       const reactions = !!cardCommentReactions ? cardCommentReactions.reactions : [];
       const userId = Meteor.userId();
       const reaction = reactions.find(r => r.reactionCodepoint === reactionCodepoint);