浏览代码

ReactiveMiniMongoIndex, added getChecklistsWithCardId

Martin Filser 2 年之前
父节点
当前提交
f80ecded0a
共有 2 个文件被更改,包括 23 次插入1 次删除
  1. 22 0
      imports/reactiveCache.js
  2. 1 1
      models/cards.js

+ 22 - 0
imports/reactiveCache.js

@@ -1107,6 +1107,28 @@ ReactiveMiniMongoIndex = {
       }
     }
     return ret;
+  },
+  getChecklistsWithCardId(cardId, addSelect = {}, options) {
+    let ret = []
+    if (cardId) {
+      const select = {addSelect, options}
+      if (!this.__checklistsWithId) {
+        this.__checklistsWithId = new DataCache(_select => {
+          const __select = Jsons.parse(_select);
+          const _checklists = ReactiveCache.getChecklists(
+            { cardId: { $exists: true },
+              ...__select.addSelect,
+            }, __select.options);
+          const _ret = _.groupBy(_checklists, 'cardId')
+          return _ret;
+        });
+      }
+      ret = this.__checklistsWithId.get(Jsons.stringify(select));
+      if (ret) {
+        ret = ret[cardId] || [];
+      }
+    }
+    return ret;
   }
 }
 

+ 1 - 1
models/cards.js

@@ -809,7 +809,7 @@ Cards.helpers({
   },
 
   checklists() {
-    const ret = ReactiveCache.getChecklists({ cardId: this.getRealId() }, { sort: { sort: 1 } });
+    const ret = ReactiveMiniMongoIndex.getChecklistsWithCardId(this.getRealId(), {}, { sort: { sort: 1 } });
     return ret;
   },