Browse Source

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

Martin Filser 2 years ago
parent
commit
c0ecfb87b0

+ 15 - 11
models/boards.js

@@ -654,7 +654,7 @@ Boards.helpers({
       cf.boardIds = [_id];
       cf.boardIds = [_id];
       cfMap[id] = CustomFields.insert(cf);
       cfMap[id] = CustomFields.insert(cf);
     });
     });
-    Cards.find({ boardId: _id }).forEach(card => {
+    ReactiveCache.getCards({ boardId: _id }).forEach(card => {
       Cards.update(card._id, {
       Cards.update(card._id, {
         $set: {
         $set: {
           customFields: card.customFields.map(cf => {
           customFields: card.customFields.map(cf => {
@@ -732,10 +732,11 @@ Boards.helpers({
   },
   },
 
 
   cards() {
   cards() {
-    return Cards.find(
+    const ret = ReactiveCache.getCards(
       { boardId: this._id, archived: false },
       { boardId: this._id, archived: false },
       { sort: { title: 1 } },
       { sort: { title: 1 } },
     );
     );
+    return ret;
   },
   },
 
 
   lists() {
   lists() {
@@ -824,7 +825,7 @@ Boards.helpers({
 
 
   activities() {
   activities() {
     let linkedBoardId = [this._id];
     let linkedBoardId = [this._id];
-    Cards.find({
+    ReactiveCache.getCards({
       "type": "cardType-linkedBoard",
       "type": "cardType-linkedBoard",
       "boardId": this._id}
       "boardId": this._id}
       ).forEach(card => {
       ).forEach(card => {
@@ -1008,7 +1009,8 @@ Boards.helpers({
       query.$or = [{ title: regex }, { description: regex }];
       query.$or = [{ title: regex }, { description: regex }];
     }
     }
 
 
-    return Cards.find(query, projection);
+    const ret = ReactiveCache.getCards(query, projection);
+    return ret;
   },
   },
 
 
   searchSwimlanes(term) {
   searchSwimlanes(term) {
@@ -1085,7 +1087,7 @@ Boards.helpers({
         { description: regex },
         { description: regex },
         { customFields: { $elemMatch: { value: regex } } },
         { customFields: { $elemMatch: { value: regex } } },
       ];
       ];
-      ret = Cards.find(query, projection);
+      ret = ReactiveCache.getCards(query, projection);
     }
     }
     return ret;
     return ret;
   },
   },
@@ -1205,7 +1207,7 @@ Boards.helpers({
   },
   },
 
 
   getNextCardNumber() {
   getNextCardNumber() {
-    const boardCards = Cards.find(
+    const boardCards = ReactiveCache.getCard(
       {
       {
         boardId: this._id
         boardId: this._id
       },
       },
@@ -1213,26 +1215,27 @@ Boards.helpers({
         sort: { cardNumber: -1 },
         sort: { cardNumber: -1 },
         limit: 1
         limit: 1
       }
       }
-    ).fetch();
+    , true);
 
 
     // If no card is assigned to the board, return 1
     // If no card is assigned to the board, return 1
-    if (!boardCards || boardCards.length === 0) {
+    if (!boardCards) {
       return 1;
       return 1;
     }
     }
 
 
-    const maxCardNr = !!boardCards[0].cardNumber ? boardCards[0].cardNumber : 0;
+    const maxCardNr = !!boardCards.cardNumber ? boardCards.cardNumber : 0;
     return maxCardNr + 1;
     return maxCardNr + 1;
   },
   },
 
 
   cardsDueInBetween(start, end) {
   cardsDueInBetween(start, end) {
-    return Cards.find({
+    const ret = ReactiveCache.getCards({
       boardId: this._id,
       boardId: this._id,
       dueAt: { $gte: start, $lte: end },
       dueAt: { $gte: start, $lte: end },
     });
     });
+    return ret;
   },
   },
 
 
   cardsInInterval(start, end) {
   cardsInInterval(start, end) {
-    return Cards.find({
+    const ret = ReactiveCache.getCards({
       boardId: this._id,
       boardId: this._id,
       $or: [
       $or: [
         {
         {
@@ -1261,6 +1264,7 @@ Boards.helpers({
         },
         },
       ],
       ],
     });
     });
+    return ret;
   },
   },
 
 
   isTemplateBoard() {
   isTemplateBoard() {

+ 23 - 20
models/cards.js

@@ -600,7 +600,7 @@ Cards.helpers({
     });
     });
 
 
     // copy subtasks
     // copy subtasks
-    Cards.find({ parentId: oldId }).forEach(subtask => {
+    ReactiveCache.getCards({ parentId: oldId }).forEach(subtask => {
       subtask.parentId = _id;
       subtask.parentId = _id;
       subtask._id = null;
       subtask._id = null;
       Cards.insert(subtask);
       Cards.insert(subtask);
@@ -865,7 +865,7 @@ Cards.helpers({
   },
   },
 
 
   subtasks() {
   subtasks() {
-    return Cards.find(
+    const ret = ReactiveCache.getCards(
       {
       {
         parentId: this._id,
         parentId: this._id,
         archived: false,
         archived: false,
@@ -876,34 +876,37 @@ Cards.helpers({
         },
         },
       },
       },
     );
     );
+    return ret;
   },
   },
 
 
   subtasksFinished() {
   subtasksFinished() {
-    return Cards.find({
+    const ret = ReactiveCache.getCards({
       parentId: this._id,
       parentId: this._id,
       archived: true,
       archived: true,
     });
     });
+    return ret;
   },
   },
 
 
   allSubtasks() {
   allSubtasks() {
-    return Cards.find({
+    const ret = ReactiveCache.getCards({
       parentId: this._id,
       parentId: this._id,
     });
     });
+    return ret;
   },
   },
 
 
   subtasksCount() {
   subtasksCount() {
     const subtasks = this.subtasks();
     const subtasks = this.subtasks();
-    return subtasks.count();
+    return subtasks.length;
   },
   },
 
 
   subtasksFinishedCount() {
   subtasksFinishedCount() {
     const subtasksArchived = this.subtasksFinished();
     const subtasksArchived = this.subtasksFinished();
-    return subtasksArchived.count();
+    return subtasksArchived.length;
   },
   },
 
 
   allSubtasksCount() {
   allSubtasksCount() {
     const allSubtasks = this.allSubtasks();
     const allSubtasks = this.allSubtasks();
-    return allSubtasks.count();
+    return allSubtasks.length;
   },
   },
 
 
   allowsSubtasks() {
   allowsSubtasks() {
@@ -990,7 +993,7 @@ Cards.helpers({
     if (
     if (
       !list.getWipLimit('soft') &&
       !list.getWipLimit('soft') &&
       list.getWipLimit('enabled') &&
       list.getWipLimit('enabled') &&
-      list.getWipLimit('value') === list.cards().count()
+      list.getWipLimit('value') === list.cards().length
     ) {
     ) {
       return false;
       return false;
     }
     }
@@ -1929,7 +1932,7 @@ Cards.helpers({
 
 
 Cards.mutations({
 Cards.mutations({
   applyToChildren(funct) {
   applyToChildren(funct) {
-    Cards.find({
+    ReactiveCache.getCards({
       parentId: this._id,
       parentId: this._id,
     }).forEach(card => {
     }).forEach(card => {
       funct(card);
       funct(card);
@@ -2963,7 +2966,7 @@ function cardRemover(userId, doc) {
 
 
 const findDueCards = days => {
 const findDueCards = days => {
   const seekDue = ($from, $to, activityType) => {
   const seekDue = ($from, $to, activityType) => {
-    Cards.find({
+    ReactiveCache.getCards({
       archived: false,
       archived: false,
       dueAt: { $gte: $from, $lt: $to },
       dueAt: { $gte: $from, $lt: $to },
     }).forEach(card => {
     }).forEach(card => {
@@ -3207,7 +3210,7 @@ if (Meteor.isServer) {
       Authentication.checkBoardAccess(req.userId, paramBoardId);
       Authentication.checkBoardAccess(req.userId, paramBoardId);
       JsonRoutes.sendResult(res, {
       JsonRoutes.sendResult(res, {
         code: 200,
         code: 200,
-        data: Cards.find({
+        data: ReactiveCache.getCards({
           boardId: paramBoardId,
           boardId: paramBoardId,
           swimlaneId: paramSwimlaneId,
           swimlaneId: paramSwimlaneId,
           archived: false,
           archived: false,
@@ -3249,7 +3252,7 @@ if (Meteor.isServer) {
     Authentication.checkBoardAccess(req.userId, paramBoardId);
     Authentication.checkBoardAccess(req.userId, paramBoardId);
     JsonRoutes.sendResult(res, {
     JsonRoutes.sendResult(res, {
       code: 200,
       code: 200,
-      data: Cards.find({
+      data: ReactiveCache.getCards({
         boardId: paramBoardId,
         boardId: paramBoardId,
         listId: paramListId,
         listId: paramListId,
         archived: false,
         archived: false,
@@ -3336,7 +3339,7 @@ if (Meteor.isServer) {
       },
       },
     );
     );
 
 
-    const currentCards = Cards.find(
+    const currentCards = ReactiveCache.getCards(
       {
       {
         listId: paramListId,
         listId: paramListId,
         archived: false,
         archived: false,
@@ -3355,7 +3358,7 @@ if (Meteor.isServer) {
         description: req.body.description,
         description: req.body.description,
         userId: req.body.authorId,
         userId: req.body.authorId,
         swimlaneId: req.body.swimlaneId,
         swimlaneId: req.body.swimlaneId,
-        sort: currentCards.count(),
+        sort: currentCards.length,
         cardNumber: nextCardNumber,
         cardNumber: nextCardNumber,
         customFields: customFieldsArr,
         customFields: customFieldsArr,
         members,
         members,
@@ -3394,10 +3397,10 @@ JsonRoutes.add('GET', '/api/boards/:boardId/cards_count', function(
     JsonRoutes.sendResult(res, {
     JsonRoutes.sendResult(res, {
       code: 200,
       code: 200,
       data: {
       data: {
-        board_cards_count: Cards.find({
+        board_cards_count: ReactiveCache.getCards({
           boardId: paramBoardId,
           boardId: paramBoardId,
           archived: false,
           archived: false,
-        }).count(),
+        }),
       }
       }
     });
     });
   } catch (error) {
   } catch (error) {
@@ -3427,11 +3430,11 @@ JsonRoutes.add('GET', '/api/boards/:boardId/cards_count', function(
       JsonRoutes.sendResult(res, {
       JsonRoutes.sendResult(res, {
         code: 200,
         code: 200,
         data: {
         data: {
-          list_cards_count: Cards.find({
+          list_cards_count: ReactiveCache.getCards({
             boardId: paramBoardId,
             boardId: paramBoardId,
             listId: paramListId,
             listId: paramListId,
             archived: false,
             archived: false,
-          }).count(),
+          }).length,
         }
         }
       });
       });
     } catch (error) {
     } catch (error) {
@@ -3901,7 +3904,7 @@ JsonRoutes.add('GET', '/api/boards/:boardId/cards_count', function(
       Authentication.checkBoardAccess(req.userId, paramBoardId);
       Authentication.checkBoardAccess(req.userId, paramBoardId);
       JsonRoutes.sendResult(res, {
       JsonRoutes.sendResult(res, {
         code: 200,
         code: 200,
-        data: Cards.find({
+        data: ReactiveCache.getCards({
           boardId: paramBoardId,
           boardId: paramBoardId,
           customFields: {
           customFields: {
             $elemMatch: {
             $elemMatch: {
@@ -3910,7 +3913,7 @@ JsonRoutes.add('GET', '/api/boards/:boardId/cards_count', function(
             },
             },
           },
           },
           archived: false,
           archived: false,
-        }).fetch(),
+        }),
       });
       });
     },
     },
   );
   );

+ 3 - 3
models/exporter.js

@@ -98,7 +98,7 @@ export class Exporter {
     }
     }
 
 
     result.lists = Lists.find(byBoard, noBoardId).fetch();
     result.lists = Lists.find(byBoard, noBoardId).fetch();
-    result.cards = Cards.find(byBoardNoLinked, noBoardId).fetch();
+    result.cards = ReactiveCache.getCards(byBoardNoLinked, noBoardId);
     result.swimlanes = Swimlanes.find(byBoard, noBoardId).fetch();
     result.swimlanes = Swimlanes.find(byBoard, noBoardId).fetch();
     result.customFields = CustomFields.find(
     result.customFields = CustomFields.find(
       { boardIds: this._boardId },
       { boardIds: this._boardId },
@@ -124,9 +124,9 @@ export class Exporter {
         }).fetch(),
         }).fetch(),
       );
       );
       result.subtaskItems.push(
       result.subtaskItems.push(
-        ...Cards.find({
+        ...ReactiveCache.getCards({
           parentId: card._id,
           parentId: card._id,
-        }).fetch(),
+        }),
       );
       );
     });
     });
     result.rules.forEach((rule) => {
     result.rules.forEach((rule) => {

+ 8 - 5
models/lists.js

@@ -209,7 +209,7 @@ Lists.helpers({
     }
     }
 
 
     // Copy all cards in list
     // Copy all cards in list
-    Cards.find({
+    ReactiveCache.getCards({
       swimlaneId: oldSwimlaneId,
       swimlaneId: oldSwimlaneId,
       listId: oldId,
       listId: oldId,
       archived: false,
       archived: false,
@@ -253,7 +253,8 @@ Lists.helpers({
       archived: false,
       archived: false,
     };
     };
     if (swimlaneId) selector.swimlaneId = swimlaneId;
     if (swimlaneId) selector.swimlaneId = swimlaneId;
-    return Cards.find(Filter.mongoSelector(selector), { sort: ['sort'] });
+    const ret = ReactiveCache.getCards(Filter.mongoSelector(selector), { sort: ['sort'] });
+    return ret;
   },
   },
 
 
   cardsUnfiltered(swimlaneId) {
   cardsUnfiltered(swimlaneId) {
@@ -262,11 +263,13 @@ Lists.helpers({
       archived: false,
       archived: false,
     };
     };
     if (swimlaneId) selector.swimlaneId = swimlaneId;
     if (swimlaneId) selector.swimlaneId = swimlaneId;
-    return Cards.find(selector, { sort: ['sort'] });
+    const ret = ReactiveCache.getCards(selector, { sort: ['sort'] });
+    return ret;
   },
   },
 
 
   allCards() {
   allCards() {
-    return Cards.find({ listId: this._id });
+    const ret = ReactiveCache.getCards({ listId: this._id });
+    return ret;
   },
   },
 
 
   board() {
   board() {
@@ -450,7 +453,7 @@ if (Meteor.isServer) {
   });
   });
 
 
   Lists.before.remove((userId, doc) => {
   Lists.before.remove((userId, doc) => {
-    const cards = Cards.find({ listId: doc._id });
+    const cards = ReactiveCache.getCards({ listId: doc._id });
     if (cards) {
     if (cards) {
       cards.forEach(card => {
       cards.forEach(card => {
         Cards.remove(card._id);
         Cards.remove(card._id);

+ 3 - 3
models/server/ExporterCardPDF.js

@@ -41,7 +41,7 @@ class ExporterCardPDF {
           }),
           }),
         );
         );
         result.lists = Lists.find(byBoard, noBoardId).fetch();
         result.lists = Lists.find(byBoard, noBoardId).fetch();
-        result.cards = Cards.find(byBoardNoLinked, noBoardId).fetch();
+        result.cards = ReactiveCache.getCards(byBoardNoLinked, noBoardId);
         result.swimlanes = Swimlanes.find(byBoard, noBoardId).fetch();
         result.swimlanes = Swimlanes.find(byBoard, noBoardId).fetch();
         result.customFields = CustomFields.find(
         result.customFields = CustomFields.find(
           {
           {
@@ -75,9 +75,9 @@ class ExporterCardPDF {
             }).fetch(),
             }).fetch(),
           );
           );
           result.subtaskItems.push(
           result.subtaskItems.push(
-            ...Cards.find({
+            ...ReactiveCache.getCards({
               parentId: card._id,
               parentId: card._id,
-            }).fetch(),
+            }),
           );
           );
         });
         });
         result.rules.forEach((rule) => {
         result.rules.forEach((rule) => {

+ 3 - 3
models/server/ExporterExcel.js

@@ -43,7 +43,7 @@ class ExporterExcel {
       }),
       }),
     );
     );
     result.lists = Lists.find(byBoard, noBoardId).fetch();
     result.lists = Lists.find(byBoard, noBoardId).fetch();
-    result.cards = Cards.find(byBoardNoLinked, noBoardId).fetch();
+    result.cards = ReactiveCache.getCards(byBoardNoLinked, noBoardId);
     result.swimlanes = Swimlanes.find(byBoard, noBoardId).fetch();
     result.swimlanes = Swimlanes.find(byBoard, noBoardId).fetch();
     result.customFields = CustomFields.find(
     result.customFields = CustomFields.find(
       {
       {
@@ -77,9 +77,9 @@ class ExporterExcel {
         }).fetch(),
         }).fetch(),
       );
       );
       result.subtaskItems.push(
       result.subtaskItems.push(
-        ...Cards.find({
+        ...ReactiveCache.getCards({
           parentId: card._id,
           parentId: card._id,
-        }).fetch(),
+        }),
       );
       );
     });
     });
     result.rules.forEach((rule) => {
     result.rules.forEach((rule) => {

+ 5 - 3
models/swimlanes.js

@@ -169,7 +169,7 @@ Swimlanes.helpers({
         });
         });
       }
       }
 
 
-      Cards.find({
+      ReactiveCache.getCards({
         listId: list._id,
         listId: list._id,
         swimlaneId: this._id,
         swimlaneId: this._id,
       }).forEach(card => {
       }).forEach(card => {
@@ -188,13 +188,14 @@ Swimlanes.helpers({
   },
   },
 
 
   cards() {
   cards() {
-    return Cards.find(
+    const ret = ReactiveCache.getCards(
       Filter.mongoSelector({
       Filter.mongoSelector({
         swimlaneId: this._id,
         swimlaneId: this._id,
         archived: false,
         archived: false,
       }),
       }),
       { sort: ['sort'] },
       { sort: ['sort'] },
     );
     );
+    return ret;
   },
   },
 
 
   lists() {
   lists() {
@@ -227,7 +228,8 @@ Swimlanes.helpers({
   },
   },
 
 
   allCards() {
   allCards() {
-    return Cards.find({ swimlaneId: this._id });
+    const ret = ReactiveCache.getCards({ swimlaneId: this._id });
+    return ret;
   },
   },
 
 
   board() {
   board() {