From 6a4b03324c9f0f04c2470171512861f71818ed11 Mon Sep 17 00:00:00 2001 From: Martin Filser Date: Sun, 19 Feb 2023 17:43:22 +0100 Subject: [PATCH] Move every Lists.find(idOrFirstObjectSelector, options) to the ReactiveCache (directory models/) --- client/components/lists/listHeader.js | 3 +-- client/lib/dialogWithBoardSwimlaneList.js | 2 +- models/boards.js | 8 ++++---- models/csvCreator.js | 4 ++-- models/exporter.js | 2 +- models/lists.js | 11 +++++------ models/server/ExporterCardPDF.js | 2 +- models/server/ExporterExcel.js | 2 +- models/swimlanes.js | 12 ++++++------ 9 files changed, 22 insertions(+), 24 deletions(-) diff --git a/client/components/lists/listHeader.js b/client/components/lists/listHeader.js index 798d336ce..339672d15 100644 --- a/client/components/lists/listHeader.js +++ b/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 ( diff --git a/client/lib/dialogWithBoardSwimlaneList.js b/client/lib/dialogWithBoardSwimlaneList.js index 9d0658e1d..130491265 100644 --- a/client/lib/dialogWithBoardSwimlaneList.js +++ b/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) {} } diff --git a/models/boards.js b/models/boards.js index 9b5cf97dc..3f768b813 100644 --- a/models/boards.js +++ b/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; }, diff --git a/models/csvCreator.js b/models/csvCreator.js index 9899d7384..e7d83331b 100644 --- a/models/csvCreator.js +++ b/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 { diff --git a/models/exporter.js b/models/exporter.js index 53fb844d1..d51942472 100644 --- a/models/exporter.js +++ b/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( diff --git a/models/lists.js b/models/lists.js index f7cdf446d..2925736d3 100644 --- a/models/lists.js +++ b/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, diff --git a/models/server/ExporterCardPDF.js b/models/server/ExporterCardPDF.js index 562468a68..530e862f1 100644 --- a/models/server/ExporterCardPDF.js +++ b/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( diff --git a/models/server/ExporterExcel.js b/models/server/ExporterExcel.js index 84e611fb4..9af7eafd1 100644 --- a/models/server/ExporterExcel.js +++ b/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( diff --git a/models/swimlanes.js b/models/swimlanes.js index 4bc6e87a6..fd8d66cd3 100644 --- a/models/swimlanes.js +++ b/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(); });