diff --git a/imports/reactiveCache.js b/imports/reactiveCache.js index 3d2733ee9..a5ed975a9 100644 --- a/imports/reactiveCache.js +++ b/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) { diff --git a/models/cardComments.js b/models/cardComments.js index e61b5ae5c..3d7b6a0ef 100644 --- a/models/cardComments.js +++ b/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);