2
0
Эх сурвалжийг харах

ReactiveMiniMongoIndex created, Javascript Index of MiniMongo Client Database

- I didn't find a solution to have indexes in MiniMongo on client. As i see /
  believe there isn't this feature yet in Meteor (v2.10).
- I got this and many more results while looking for an solution:

  https://forums.meteor.com/t/adding-indexing-to-minimongo/9130/12
  https://github.com/meteor/meteor-feature-requests/issues/66

So to speed up the MiniMongo i decided to create a own class for this,
currently per query. Of course, this isn't the best solution, but works for now
good.
Martin Filser 2 жил өмнө
parent
commit
40a5422e75
2 өөрчлөгдсөн 32 нэмэгдсэн , 12 устгасан
  1. 27 1
      imports/reactiveCache.js
  2. 5 11
      models/cards.js

+ 27 - 1
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 };

+ 5 - 11
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;
   },