소스 검색

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

Martin Filser 2 년 전
부모
커밋
6a4b03324c

+ 1 - 2
client/components/lists/listHeader.js

@@ -246,8 +246,7 @@ BlazeComponent.extendComponent({
 Template.listMorePopup.events({
   'click .js-delete': Popup.afterConfirm('listDelete', function() {
     Popup.back();
-    // TODO how can we avoid the fetch call?
-    const allCards = this.allCards().fetch();
+    const allCards = this.allCards();
     const allCardIds = _.pluck(allCards, '_id');
     // it's okay if the linked cards are on the same list
     if (

+ 1 - 1
client/lib/dialogWithBoardSwimlaneList.js

@@ -73,7 +73,7 @@ export class DialogWithBoardSwimlaneList extends BlazeComponent {
   setFirstListId() {
     try {
       const board = ReactiveCache.getBoard(this.selectedBoardId.get());
-      const listId = board.lists().fetch()[0]._id;
+      const listId = board.lists()[0]._id;
       this.selectedListId.set(listId);
     } catch (e) {}
   }

+ 4 - 4
models/boards.js

@@ -747,7 +747,7 @@ Boards.helpers({
     // sorted lists from newest to the oldest, by its creation date or its cards' last modification date
     const value = ReactiveCache.getCurrentUser()._getListSortBy();
     const sortKey = { starred: -1, [value[0]]: value[1] }; // [["starred",-1],value];
-    return Lists.find(
+    return ReactiveCache.getLists(
       {
         boardId: this._id,
         archived: false,
@@ -757,7 +757,7 @@ Boards.helpers({
   },
 
   draggableLists() {
-    return Lists.find({ boardId: this._id }, { sort: { sort: 1 } });
+    return ReactiveCache.getLists({ boardId: this._id }, { sort: { sort: 1 } });
   },
 
   /** returns the last list
@@ -769,7 +769,7 @@ Boards.helpers({
   },
 
   nullSortLists() {
-    return Lists.find({
+    return ReactiveCache.getLists({
       boardId: this._id,
       archived: false,
       sort: { $eq: null },
@@ -1056,7 +1056,7 @@ Boards.helpers({
         query.$or = [{ title: regex }, { description: regex }];
       }
 
-      ret = Lists.find(query, projection);
+      ret = ReactiveCache.getLists(query, projection);
     }
     return ret;
   },

+ 2 - 2
models/csvCreator.js

@@ -256,10 +256,10 @@ export class CsvCreator {
         createdAt: this._now(),
       };
       if (csvData[i][this.fieldIndex.stage]) {
-        const existingList = Lists.find({
+        const existingList = ReactiveCache.getLists({
           title: csvData[i][this.fieldIndex.stage],
           boardId,
-        }).fetch();
+        });
         if (existingList.length > 0) {
           continue;
         } else {

+ 1 - 1
models/exporter.js

@@ -97,7 +97,7 @@ export class Exporter {
       return result.attachments.length > 0 ? result.attachments[0] : {};
     }
 
-    result.lists = Lists.find(byBoard, noBoardId).fetch();
+    result.lists = ReactiveCache.getLists(byBoard, noBoardId);
     result.cards = ReactiveCache.getCards(byBoardNoLinked, noBoardId);
     result.swimlanes = Swimlanes.find(byBoard, noBoardId).fetch();
     result.customFields = CustomFields.find(

+ 5 - 6
models/lists.js

@@ -365,7 +365,7 @@ Lists.mutations({
 });
 
 Lists.userArchivedLists = userId => {
-  return Lists.find({
+  return ReactiveCache.getLists({
     boardId: { $in: Boards.userBoardIds(userId, null) },
     archived: true,
   })
@@ -376,7 +376,7 @@ Lists.userArchivedListIds = () => {
 };
 
 Lists.archivedLists = () => {
-  return Lists.find({ archived: true });
+  return ReactiveCache.getLists({ archived: true });
 };
 
 Lists.archivedListIds = () => {
@@ -413,7 +413,7 @@ Meteor.methods({
   myLists() {
     // my lists
     return _.uniq(
-      Lists.find(
+      ReactiveCache.getLists(
         {
           boardId: { $in: Boards.userBoardIds(this.userId) },
           archived: false,
@@ -422,7 +422,6 @@ Meteor.methods({
           fields: { title: 1 },
         },
       )
-        .fetch()
         .map(list => {
           return list.title;
         }),
@@ -502,7 +501,7 @@ if (Meteor.isServer) {
 
       JsonRoutes.sendResult(res, {
         code: 200,
-        data: Lists.find({ boardId: paramBoardId, archived: false }).map(
+        data: ReactiveCache.getLists({ boardId: paramBoardId, archived: false }).map(
           function(doc) {
             return {
               _id: doc._id,
@@ -567,7 +566,7 @@ if (Meteor.isServer) {
       const id = Lists.insert({
         title: req.body.title,
         boardId: paramBoardId,
-        sort: board.lists().count(),
+        sort: board.lists().length,
       });
       JsonRoutes.sendResult(res, {
         code: 200,

+ 1 - 1
models/server/ExporterCardPDF.js

@@ -40,7 +40,7 @@ class ExporterCardPDF {
             },
           }),
         );
-        result.lists = Lists.find(byBoard, noBoardId).fetch();
+        result.lists = ReactiveCache.getLists(byBoard, noBoardId);
         result.cards = ReactiveCache.getCards(byBoardNoLinked, noBoardId);
         result.swimlanes = Swimlanes.find(byBoard, noBoardId).fetch();
         result.customFields = CustomFields.find(

+ 1 - 1
models/server/ExporterExcel.js

@@ -42,7 +42,7 @@ class ExporterExcel {
         },
       }),
     );
-    result.lists = Lists.find(byBoard, noBoardId).fetch();
+    result.lists = ReactiveCache.getLists(byBoard, noBoardId);
     result.cards = ReactiveCache.getCards(byBoardNoLinked, noBoardId);
     result.swimlanes = Swimlanes.find(byBoard, noBoardId).fetch();
     result.customFields = CustomFields.find(

+ 6 - 6
models/swimlanes.js

@@ -140,7 +140,7 @@ Swimlanes.helpers({
     }
 
     // Copy all lists in swimlane
-    Lists.find(query).forEach(list => {
+    ReactiveCache.getLists(query).forEach(list => {
       list.type = 'list';
       list.swimlaneId = oldId;
       list.boardId = boardId;
@@ -203,7 +203,7 @@ Swimlanes.helpers({
   },
   newestLists() {
     // sorted lists from newest to the oldest, by its creation date or its cards' last modification date
-    return Lists.find(
+    return ReactiveCache.getLists(
       {
         boardId: this.boardId,
         swimlaneId: { $in: [this._id, ''] },
@@ -213,7 +213,7 @@ Swimlanes.helpers({
     );
   },
   draggableLists() {
-    return Lists.find(
+    return ReactiveCache.getLists(
       {
         boardId: this.boardId,
         swimlaneId: { $in: [this._id, ''] },
@@ -224,7 +224,7 @@ Swimlanes.helpers({
   },
 
   myLists() {
-    return Lists.find({ swimlaneId: this._id });
+    return ReactiveCache.getLists({ swimlaneId: this._id });
   },
 
   allCards() {
@@ -344,7 +344,7 @@ if (Meteor.isServer) {
   });
 
   Swimlanes.before.remove(function(userId, doc) {
-    const lists = Lists.find(
+    const lists = ReactiveCache.getLists(
       {
         boardId: doc.boardId,
         swimlaneId: { $in: [doc._id, ''] },
@@ -353,7 +353,7 @@ if (Meteor.isServer) {
       { sort: ['sort'] },
     );
 
-    if (lists.count() < 2) {
+    if (lists.length < 2) {
       lists.forEach(list => {
         list.remove();
       });