Move every Cards.findOne() to the ReactiveCache

This commit is contained in:
Martin Filser 2022-12-16 16:36:47 +01:00
parent a182482cfb
commit 3b65113d05
24 changed files with 96 additions and 87 deletions

View file

@ -38,7 +38,7 @@ Activities.helpers({
return Lists.findOne(this.oldListId);
},
card() {
return Cards.findOne(this.cardId);
return ReactiveCache.getCard(this.cardId);
},
comment() {
return CardComments.findOne(this.commentId);
@ -53,14 +53,14 @@ Activities.helpers({
return ChecklistItems.findOne(this.checklistItemId);
},
subtasks() {
return Cards.findOne(this.subtaskId);
return ReactiveCache.getCard(this.subtaskId);
},
customField() {
return CustomFields.findOne(this.customFieldId);
},
// Label activity did not work yet, unable to edit labels when tried this.
//label() {
// return Cards.findOne(this.labelId);
// return ReactiveCache.getCard(this.labelId);
//},
});

View file

@ -147,7 +147,7 @@ CardComments.helpers({
CardComments.hookOptions.after.update = { fetchPrevious: false };
function commentCreation(userId, doc) {
const card = Cards.findOne(doc.cardId);
const card = ReactiveCache.getCard(doc.cardId);
Activities.insert({
userId,
activityType: 'addComment',
@ -194,7 +194,7 @@ if (Meteor.isServer) {
});
CardComments.after.update((userId, doc) => {
const card = Cards.findOne(doc.cardId);
const card = ReactiveCache.getCard(doc.cardId);
Activities.insert({
userId,
activityType: 'editComment',
@ -207,7 +207,7 @@ if (Meteor.isServer) {
});
CardComments.before.remove((userId, doc) => {
const card = Cards.findOne(doc.cardId);
const card = ReactiveCache.getCard(doc.cardId);
Activities.insert({
userId,
activityType: 'deleteComment',

View file

@ -549,7 +549,7 @@ Cards.helpers({
copy(boardId, swimlaneId, listId) {
const oldId = this._id;
const oldCard = Cards.findOne(oldId);
const oldCard = ReactiveCache.getCard(oldId);
// we must only copy the labels and custom fields if the target board
// differs from the source board
@ -1001,7 +1001,7 @@ Cards.helpers({
if (this.parentId === '') {
return null;
}
return Cards.findOne(this.parentId);
return ReactiveCache.getCard(this.parentId);
},
parentCardName() {
@ -1019,7 +1019,7 @@ Cards.helpers({
const result = [];
let crtParentId = this.parentId;
while (crtParentId !== '') {
const crt = Cards.findOne(crtParentId);
const crt = ReactiveCache.getCard(crtParentId);
if (crt === null || crt === undefined) {
// maybe it has been deleted
break;
@ -1039,7 +1039,7 @@ Cards.helpers({
const result = [];
let crtParentId = this.parentId;
while (crtParentId !== '') {
const crt = Cards.findOne(crtParentId);
const crt = ReactiveCache.getCard(crtParentId);
if (crt === null || crt === undefined) {
// maybe it has been deleted
break;
@ -1089,7 +1089,7 @@ Cards.helpers({
getDescription() {
if (this.isLinkedCard()) {
const card = Cards.findOne({ _id: this.linkedId });
const card = ReactiveCache.getCard(this.linkedId);
if (card && card.description) return card.description;
else return null;
} else if (this.isLinkedBoard()) {
@ -1105,7 +1105,7 @@ Cards.helpers({
getMembers() {
if (this.isLinkedCard()) {
const card = Cards.findOne({ _id: this.linkedId });
const card = ReactiveCache.getCard(this.linkedId);
if (card === undefined) {
return null;
} else {
@ -1127,7 +1127,7 @@ Cards.helpers({
getAssignees() {
if (this.isLinkedCard()) {
const card = Cards.findOne({ _id: this.linkedId });
const card = ReactiveCache.getCard(this.linkedId);
if (card === undefined) {
return null;
} else {
@ -1227,7 +1227,7 @@ Cards.helpers({
getReceived() {
if (this.isLinkedCard()) {
const card = Cards.findOne({ _id: this.linkedId });
const card = ReactiveCache.getCard(this.linkedId);
if (card === undefined) {
return null;
} else {
@ -1255,7 +1255,7 @@ Cards.helpers({
getStart() {
if (this.isLinkedCard()) {
const card = Cards.findOne({ _id: this.linkedId });
const card = ReactiveCache.getCard(this.linkedId);
if (card === undefined) {
return null;
} else {
@ -1283,7 +1283,7 @@ Cards.helpers({
getDue() {
if (this.isLinkedCard()) {
const card = Cards.findOne({ _id: this.linkedId });
const card = ReactiveCache.getCard(this.linkedId);
if (card === undefined) {
return null;
} else {
@ -1311,7 +1311,7 @@ Cards.helpers({
getEnd() {
if (this.isLinkedCard()) {
const card = Cards.findOne({ _id: this.linkedId });
const card = ReactiveCache.getCard(this.linkedId);
if (card === undefined) {
return null;
} else {
@ -1339,7 +1339,7 @@ Cards.helpers({
getIsOvertime() {
if (this.isLinkedCard()) {
const card = Cards.findOne({ _id: this.linkedId });
const card = ReactiveCache.getCard(this.linkedId);
if (card === undefined) {
return null;
} else {
@ -1367,7 +1367,7 @@ Cards.helpers({
getSpentTime() {
if (this.isLinkedCard()) {
const card = Cards.findOne({ _id: this.linkedId });
const card = ReactiveCache.getCard(this.linkedId);
if (card === undefined) {
return null;
} else {
@ -1395,7 +1395,7 @@ Cards.helpers({
getVoteQuestion() {
if (this.isLinkedCard()) {
const card = Cards.findOne({ _id: this.linkedId });
const card = ReactiveCache.getCard(this.linkedId);
if (card === undefined) {
return null;
} else if (card && card.vote) {
@ -1421,7 +1421,7 @@ Cards.helpers({
getVotePublic() {
if (this.isLinkedCard()) {
const card = Cards.findOne({ _id: this.linkedId });
const card = ReactiveCache.getCard(this.linkedId);
if (card === undefined) {
return null;
} else if (card && card.vote) {
@ -1447,7 +1447,7 @@ Cards.helpers({
getVoteEnd() {
if (this.isLinkedCard()) {
const card = Cards.findOne({ _id: this.linkedId });
const card = ReactiveCache.getCard(this.linkedId);
if (card === undefined) {
return null;
} else if (card && card.vote) {
@ -1507,7 +1507,7 @@ Cards.helpers({
getPokerQuestion() {
if (this.isLinkedCard()) {
const card = Cards.findOne({ _id: this.linkedId });
const card = ReactiveCache.getCard(this.linkedId);
if (card === undefined) {
return null;
} else if (card && card.poker) {
@ -1541,7 +1541,7 @@ Cards.helpers({
getPokerEnd() {
if (this.isLinkedCard()) {
const card = Cards.findOne({ _id: this.linkedId });
const card = ReactiveCache.getCard(this.linkedId);
if (card === undefined) {
return null;
} else if (card && card.poker) {
@ -1692,7 +1692,7 @@ Cards.helpers({
getTitle() {
if (this.isLinkedCard()) {
const card = Cards.findOne({ _id: this.linkedId });
const card = ReactiveCache.getCard(this.linkedId);
if (card === undefined) {
return null;
} else {
@ -1718,7 +1718,7 @@ Cards.helpers({
getBoardTitle() {
if (this.isLinkedCard()) {
const card = Cards.findOne({ _id: this.linkedId });
const card = ReactiveCache.getCard(this.linkedId);
if (card === undefined) {
return null;
}
@ -1755,7 +1755,7 @@ Cards.helpers({
getArchived() {
if (this.isLinkedCard()) {
const card = Cards.findOne({ _id: this.linkedId });
const card = ReactiveCache.getCard(this.linkedId);
if (card === undefined) {
return null;
} else {
@ -1779,7 +1779,7 @@ Cards.helpers({
getRequestedBy() {
if (this.isLinkedCard()) {
const card = Cards.findOne({ _id: this.linkedId });
const card = ReactiveCache.getCard(this.linkedId);
if (card === undefined) {
return null;
} else {
@ -1796,7 +1796,7 @@ Cards.helpers({
getAssignedBy() {
if (this.isLinkedCard()) {
const card = Cards.findOne({ _id: this.linkedId });
const card = ReactiveCache.getCard(this.linkedId);
if (card === undefined) {
return null;
} else {
@ -3057,7 +3057,7 @@ if (Meteor.isServer) {
check(insertAtTop, Boolean);
check(mergeCardValues, Object);
const card = Cards.findOne({_id: cardId});
const card = ReactiveCache.getCard(cardId);
Object.assign(card, mergeCardValues);
const sort = card.getSort(listId, swimlaneId, insertAtTop);
@ -3140,7 +3140,7 @@ if (Meteor.isServer) {
const value = modifier.$set[action];
const oldvalue = doc[action] || '';
const activityType = `a-${action}`;
const card = Cards.findOne(doc._id);
const card = ReactiveCache.getCard(doc._id);
const list = card.list();
if (list) {
// change list modifiedAt, when user modified the key values in
@ -3370,9 +3370,7 @@ if (Meteor.isServer) {
},
});
const card = Cards.findOne({
_id: id,
});
const card = ReactiveCache.getCard(id);
cardCreation(req.body.authorId, card);
} else {
JsonRoutes.sendResult(res, {
@ -3826,9 +3824,7 @@ JsonRoutes.add('GET', '/api/boards/:boardId/cards_count', function(
},
);
const card = Cards.findOne({
_id: paramCardId,
});
const card = ReactiveCache.getCard(paramCardId);
cardMove(
req.body.authorId,
card,
@ -3868,9 +3864,7 @@ JsonRoutes.add('GET', '/api/boards/:boardId/cards_count', function(
const paramCardId = req.params.cardId;
Authentication.checkBoardAccess(req.userId, paramBoardId);
const card = Cards.findOne({
_id: paramCardId,
});
const card = ReactiveCache.getCard(paramCardId);
Cards.direct.remove({
_id: paramCardId,
listId: paramListId,

View file

@ -1,3 +1,5 @@
import { ReactiveCache } from '/imports/reactiveCache';
ChecklistItems = new Mongo.Collection('checklistItems');
/**
@ -68,13 +70,13 @@ ChecklistItems.attachSchema(
ChecklistItems.allow({
insert(userId, doc) {
return allowIsBoardMemberByCard(userId, Cards.findOne(doc.cardId));
return allowIsBoardMemberByCard(userId, ReactiveCache.getCard(doc.cardId));
},
update(userId, doc) {
return allowIsBoardMemberByCard(userId, Cards.findOne(doc.cardId));
return allowIsBoardMemberByCard(userId, ReactiveCache.getCard(doc.cardId));
},
remove(userId, doc) {
return allowIsBoardMemberByCard(userId, Cards.findOne(doc.cardId));
return allowIsBoardMemberByCard(userId, ReactiveCache.getCard(doc.cardId));
},
fetch: ['userId', 'cardId'],
});
@ -113,7 +115,7 @@ ChecklistItems.mutations({
// Activities helper
function itemCreation(userId, doc) {
const card = Cards.findOne(doc.cardId);
const card = ReactiveCache.getCard(doc.cardId);
const boardId = card.boardId;
Activities.insert({
userId,
@ -135,7 +137,7 @@ function itemRemover(userId, doc) {
}
function publishCheckActivity(userId, doc) {
const card = Cards.findOne(doc.cardId);
const card = ReactiveCache.getCard(doc.cardId);
const boardId = card.boardId;
let activityType;
if (doc.isFinished) {
@ -158,7 +160,7 @@ function publishCheckActivity(userId, doc) {
}
function publishChekListCompleted(userId, doc) {
const card = Cards.findOne(doc.cardId);
const card = ReactiveCache.getCard(doc.cardId);
const boardId = card.boardId;
const checklistId = doc.checklistId;
const checkList = Checklists.findOne({ _id: checklistId });
@ -178,7 +180,7 @@ function publishChekListCompleted(userId, doc) {
}
function publishChekListUncompleted(userId, doc) {
const card = Cards.findOne(doc.cardId);
const card = ReactiveCache.getCard(doc.cardId);
const boardId = card.boardId;
const checklistId = doc.checklistId;
const checkList = Checklists.findOne({ _id: checklistId });
@ -233,7 +235,7 @@ if (Meteor.isServer) {
ChecklistItems.before.remove((userId, doc) => {
itemRemover(userId, doc);
const card = Cards.findOne(doc.cardId);
const card = ReactiveCache.getCard(doc.cardId);
const boardId = card.boardId;
Activities.insert({
userId,

View file

@ -148,13 +148,13 @@ Checklists.helpers({
Checklists.allow({
insert(userId, doc) {
return allowIsBoardMemberByCard(userId, Cards.findOne(doc.cardId));
return allowIsBoardMemberByCard(userId, ReactiveCache.getCard(doc.cardId));
},
update(userId, doc) {
return allowIsBoardMemberByCard(userId, Cards.findOne(doc.cardId));
return allowIsBoardMemberByCard(userId, ReactiveCache.getCard(doc.cardId));
},
remove(userId, doc) {
return allowIsBoardMemberByCard(userId, Cards.findOne(doc.cardId));
return allowIsBoardMemberByCard(userId, ReactiveCache.getCard(doc.cardId));
},
fetch: ['userId', 'cardId'],
});
@ -210,7 +210,7 @@ if (Meteor.isServer) {
});
Checklists.after.insert((userId, doc) => {
const card = Cards.findOne(doc.cardId);
const card = ReactiveCache.getCard(doc.cardId);
Activities.insert({
userId,
activityType: 'addChecklist',
@ -225,7 +225,7 @@ if (Meteor.isServer) {
Checklists.before.remove((userId, doc) => {
const activities = Activities.find({ checklistId: doc._id });
const card = Cards.findOne(doc.cardId);
const card = ReactiveCache.getCard(doc.cardId);
if (activities) {
activities.forEach(activity => {
Activities.remove(activity._id);
@ -235,7 +235,7 @@ if (Meteor.isServer) {
userId,
activityType: 'removeChecklist',
cardId: doc.cardId,
boardId: Cards.findOne(doc.cardId).boardId,
boardId: ReactiveCache.getCard(doc.cardId).boardId,
checklistId: doc._id,
checklistName: doc.title,
listId: card.listId,

View file

@ -218,7 +218,7 @@ function customFieldDeletion(userId, doc) {
// This has some bug, it does not show edited customField value at Outgoing Webhook,
// instead it shows undefined, and no listId and swimlaneId.
function customFieldEdit(userId, doc) {
const card = Cards.findOne(doc.cardId);
const card = ReactiveCache.getCard(doc.cardId);
const customFieldValue = Activities.findOne({ customFieldId: doc._id }).value;
Activities.insert({
userId,

View file

@ -613,7 +613,7 @@ export class WekanCreator {
: card.parentId;
//if the parent card exists, proceed
if (Cards.findOne(parentIdInNewBoard)) {
if (ReactiveCache.getCard(parentIdInNewBoard)) {
//set parent id of the card in the new board to the new id of the parent
Cards.direct.update(cardIdInNewBoard, {
$set: {