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

This commit is contained in:
Martin Filser 2023-02-19 17:43:22 +01:00
parent 4a8dcde8ee
commit 6a4b03324c
9 changed files with 22 additions and 24 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -97,7 +97,7 @@ export class Exporter {
return result.attachments.length > 0 ? result.attachments[0] : {}; 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.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(

View file

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

View file

@ -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.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(

View file

@ -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.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(

View file

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