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

This commit is contained in:
Martin Filser 2023-02-14 18:52:36 +01:00
parent 7673c77c57
commit c0ecfb87b0
7 changed files with 60 additions and 48 deletions

View file

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

View file

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

View file

@ -98,7 +98,7 @@ export class Exporter {
}
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.customFields = CustomFields.find(
{ boardIds: this._boardId },
@ -124,9 +124,9 @@ export class Exporter {
}).fetch(),
);
result.subtaskItems.push(
...Cards.find({
...ReactiveCache.getCards({
parentId: card._id,
}).fetch(),
}),
);
});
result.rules.forEach((rule) => {

View file

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

View file

@ -41,7 +41,7 @@ class ExporterCardPDF {
}),
);
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.customFields = CustomFields.find(
{
@ -75,9 +75,9 @@ class ExporterCardPDF {
}).fetch(),
);
result.subtaskItems.push(
...Cards.find({
...ReactiveCache.getCards({
parentId: card._id,
}).fetch(),
}),
);
});
result.rules.forEach((rule) => {

View file

@ -43,7 +43,7 @@ class ExporterExcel {
}),
);
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.customFields = CustomFields.find(
{
@ -77,9 +77,9 @@ class ExporterExcel {
}).fetch(),
);
result.subtaskItems.push(
...Cards.find({
...ReactiveCache.getCards({
parentId: card._id,
}).fetch(),
}),
);
});
result.rules.forEach((rule) => {

View file

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