diff --git a/imports/reactiveCache.js b/imports/reactiveCache.js index 4674e9485..e6ea29439 100644 --- a/imports/reactiveCache.js +++ b/imports/reactiveCache.js @@ -1084,4 +1084,30 @@ ReactiveCache = { }, } -export { ReactiveCache }; +// Client side little MiniMongo DB "Index" +ReactiveMiniMongoIndex = { + getSubTasksWithParentId(parentId, addSelect = {}, options) { + let ret = [] + if (parentId) { + const select = {addSelect, options} + if (!this.__subTasksWithId) { + this.__subTasksWithId = new DataCache(_select => { + const __select = Jsons.parse(_select); + const _subTasks = ReactiveCache.getCards( + { parentId: { $exists: true }, + ...__select.addSelect, + }, __select.options); + const _ret = _.groupBy(_subTasks, 'parentId') + return _ret; + }); + } + ret = this.__subTasksWithId.get(Jsons.stringify(select)); + if (ret) { + ret = ret[parentId] || []; + } + } + return ret; + } +} + +export { ReactiveCache, ReactiveMiniMongoIndex }; diff --git a/models/cards.js b/models/cards.js index 8cc5968e2..5e5f50f39 100644 --- a/models/cards.js +++ b/models/cards.js @@ -1,4 +1,4 @@ -import { ReactiveCache } from '/imports/reactiveCache'; +import { ReactiveCache, ReactiveMiniMongoIndex } from '/imports/reactiveCache'; import moment from 'moment/min/moment-with-locales'; import { ALLOWED_COLORS, @@ -861,12 +861,9 @@ Cards.helpers({ }, subtasks() { - const ret = ReactiveCache.getCards( - { - parentId: this._id, + const ret = ReactiveMiniMongoIndex.getSubTasksWithParentId(this._id, { archived: false, - }, - { + }, { sort: { sort: 1, }, @@ -876,17 +873,14 @@ Cards.helpers({ }, subtasksFinished() { - const ret = ReactiveCache.getCards({ - parentId: this._id, + const ret = ReactiveMiniMongoIndex.getSubTasksWithParentId(this._id, { archived: true, }); return ret; }, allSubtasks() { - const ret = ReactiveCache.getCards({ - parentId: this._id, - }); + const ret = ReactiveMiniMongoIndex.getSubTasksWithParentId(this._id); return ret; },