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

This commit is contained in:
Martin Filser 2023-02-05 00:10:46 +01:00
parent f5796faa84
commit e30edce73e
2 changed files with 52 additions and 2 deletions

View file

@ -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) {

View file

@ -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);