Browse Source

Move every ChecklistItems.find(idOrFirstObjectSelector, options) to the ReactiveCache (directory models/)

Martin Filser 2 years ago
parent
commit
6fd3c0fa6b
4 changed files with 18 additions and 23 deletions
  1. 12 17
      models/checklists.js
  2. 2 2
      models/exporter.js
  3. 2 2
      models/server/ExporterCardPDF.js
  4. 2 2
      models/server/ExporterExcel.js

+ 12 - 17
models/checklists.js

@@ -1,5 +1,4 @@
 import { ReactiveCache } from '/imports/reactiveCache';
-import { DataCache } from 'meteor-reactive-cache'
 
 Checklists = new Mongo.Collection('checklists');
 
@@ -73,7 +72,7 @@ Checklists.helpers({
     delete copyObj._id;
     copyObj.cardId = newCardId;
     const newChecklistId = Checklists.insert(copyObj);
-    ChecklistItems.find({ checklistId: this._id }).forEach(function(
+    ReactiveCache.getChecklistItems({ checklistId: this._id }).forEach(function(
       item,
     ) {
       item._id = null;
@@ -88,18 +87,14 @@ Checklists.helpers({
     return ret;
   },
   items() {
-    if (!this._items) {
-      this._items = new DataCache(() => ChecklistItems.find(
-        {
-          checklistId: this._id,
-        },
-        { sort: ['sort'] },
+    const ret = ReactiveCache.getChecklistItems(
+      {
+        checklistId: this._id,
+      },
+      { sort: ['sort'] },
+    );
+    return ret;
 
-      )
-      .fetch()
-      , 1000);
-    }
-    return this._items.get();
   },
   firstItem() {
     const ret = _.first(this.items());
@@ -129,13 +124,13 @@ Checklists.helpers({
     return 0 !== this.itemCount() && this.itemCount() === this.finishedCount();
   },
   checkAllItems() {
-    const checkItems = ChecklistItems.find({ checklistId: this._id });
+    const checkItems = ReactiveCache.getChecklistItems({ checklistId: this._id });
     checkItems.forEach(function(item) {
       item.check();
     });
   },
   uncheckAllItems() {
-    const checkItems = ChecklistItems.find({ checklistId: this._id });
+    const checkItems = ReactiveCache.getChecklistItems({ checklistId: this._id });
     checkItems.forEach(function(item) {
       item.uncheck();
     });
@@ -185,7 +180,7 @@ Checklists.mutations({
       });
     });
     // update every checklist-item
-    ChecklistItems.find(
+    ReactiveCache.getChecklistItems(
       {checklistId: this._id}
     ).forEach(checklistItem => {
       ChecklistItems.update(checklistItem._id, {
@@ -311,7 +306,7 @@ if (Meteor.isServer) {
         cardId: paramCardId,
       });
       if (checklist) {
-        checklist.items = ChecklistItems.find({
+        checklist.items = ReactiveCache.getChecklistItems({
           checklistId: checklist._id,
         }).map(function(doc) {
           return {

+ 2 - 2
models/exporter.js

@@ -119,9 +119,9 @@ export class Exporter {
         }).fetch(),
       );
       result.checklistItems.push(
-        ...ChecklistItems.find({
+        ...ReactiveCache.getChecklistItems({
           cardId: card._id,
-        }).fetch(),
+        }),
       );
       result.subtaskItems.push(
         ...ReactiveCache.getCards({

+ 2 - 2
models/server/ExporterCardPDF.js

@@ -70,9 +70,9 @@ class ExporterCardPDF {
             }).fetch(),
           );
           result.checklistItems.push(
-            ...ChecklistItems.find({
+            ...ReactiveCache.getChecklistItems({
               cardId: card._id,
-            }).fetch(),
+            }),
           );
           result.subtaskItems.push(
             ...ReactiveCache.getCards({

+ 2 - 2
models/server/ExporterExcel.js

@@ -72,9 +72,9 @@ class ExporterExcel {
         }).fetch(),
       );
       result.checklistItems.push(
-        ...ChecklistItems.find({
+        ...ReactiveCache.getChecklistItems({
           cardId: card._id,
-        }).fetch(),
+        }),
       );
       result.subtaskItems.push(
         ...ReactiveCache.getCards({