From 42fad8fb9845024b4e88633126f5bae9a8563ba4 Mon Sep 17 00:00:00 2001 From: Martin Filser Date: Sun, 5 Mar 2023 17:35:07 +0100 Subject: [PATCH] ReactiveMiniMongoIndex, added getCardCommentsWithCardId --- imports/reactiveCache.js | 22 ++++++++++++++++++++++ models/cards.js | 5 +++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/imports/reactiveCache.js b/imports/reactiveCache.js index f4a102dd1..6be1328f5 100644 --- a/imports/reactiveCache.js +++ b/imports/reactiveCache.js @@ -1151,6 +1151,28 @@ ReactiveMiniMongoIndex = { } } return ret; + }, + getCardCommentsWithCardId(cardId, addSelect = {}, options) { + let ret = [] + if (cardId) { + const select = {addSelect, options} + if (!this.__cardCommentsWithId) { + this.__cardCommentsWithId = new DataCache(_select => { + const __select = Jsons.parse(_select); + const _cardComments = ReactiveCache.getCardComments( + { cardId: { $exists: true }, + ...__select.addSelect, + }, __select.options); + const _ret = _.groupBy(_cardComments, 'cardId') + return _ret; + }); + } + ret = this.__cardCommentsWithId.get(Jsons.stringify(select)); + if (ret) { + ret = ret[cardId] || []; + } + } + return ret; } } diff --git a/models/cards.js b/models/cards.js index ae50b1ac2..f1b0f6656 100644 --- a/models/cards.js +++ b/models/cards.js @@ -784,8 +784,9 @@ Cards.helpers({ { sort: { createdAt: -1 } }, ); } else { - ret = ReactiveCache.getCardComments( - { cardId: this.getRealId() }, + ret = ReactiveMiniMongoIndex.getCardCommentsWithCardId( + this.getRealId(), + {}, { sort: { createdAt: -1 } }, ); }