Move every Boards.findOne(boardId) to the ReactiveCache (Part 2)

This commit is contained in:
Martin Filser 2023-01-14 13:29:57 +01:00
parent 9022e9949f
commit a182482cfb
37 changed files with 166 additions and 127 deletions

View file

@ -1,3 +1,4 @@
import { ReactiveCache } from '/imports/reactiveCache';
import DOMPurify from 'dompurify';
import { TAPi18n } from '/imports/i18n';
@ -145,7 +146,7 @@ BlazeComponent.extendComponent({
lastLabel() {
const lastLabelId = this.currentData().activity.labelId;
if (!lastLabelId) return null;
const lastLabel = Boards.findOne(
const lastLabel = ReactiveCache.getBoard(
this.currentData().activity.boardId,
).getLabelById(lastLabelId);
if (lastLabel && (lastLabel.name === undefined || lastLabel.name === '')) {

View file

@ -1,3 +1,4 @@
import { ReactiveCache } from '/imports/reactiveCache';
import { TAPi18n } from '/imports/i18n';
const subManager = new SubsManager();
@ -223,8 +224,8 @@ BlazeComponent.extendComponent({
boardMembers(boardId) {
let boardMembers = [];
/* Bug Board icons random dance https://github.com/wekan/wekan/issues/4214
const lists = Boards.findOne({ '_id': boardId })
let members = lists.members;
const lists = ReactiveCache.getBoard(boardId)
let members = lists.members
members.forEach(member => {
boardMembers.push(member.userId);
});
@ -266,14 +267,14 @@ BlazeComponent.extendComponent({
evt.preventDefault();
},
'click .js-clone-board'(evt) {
let title = getSlug(Boards.findOne(this.currentData()._id).title) || 'cloned-board';
let title = getSlug(ReactiveCache.getBoard(this.currentData()._id).title) || 'cloned-board';
Meteor.call(
'copyBoard',
this.currentData()._id,
{
sort: Boards.find({ archived: false }).count(),
type: 'board',
title: Boards.findOne(this.currentData()._id).title,
title: ReactiveCache.getBoard(this.currentData()._id).title,
},
(err, res) => {
if (err) {

View file

@ -1,3 +1,4 @@
import { ReactiveCache } from '/imports/reactiveCache';
import moment from 'moment/min/moment-with-locales';
import { TAPi18n } from '/imports/i18n';
import { DatePicker } from '/client/lib/datepicker';
@ -143,7 +144,7 @@ BlazeComponent.extendComponent({
const card = this.currentData();
let result = '#';
if (card) {
const board = Boards.findOne(card.boardId);
const board = ReactiveCache.getBoard(card.boardId);
if (board) {
result = FlowRouter.path('card', {
boardId: card.boardId,

View file

@ -1,3 +1,4 @@
import { ReactiveCache } from '/imports/reactiveCache';
import { TAPi18n } from '/imports/i18n';
import Cards from '/models/cards';
import Boards from '/models/boards';
@ -243,12 +244,12 @@ BlazeComponent.extendComponent({
},
swimlanes() {
const board = Boards.findOne(this.selectedBoardId.get());
const board = ReactiveCache.getBoard(this.selectedBoardId.get());
return board.swimlanes();
},
aBoardLists() {
const board = Boards.findOne(this.selectedBoardId.get());
const board = ReactiveCache.getBoard(this.selectedBoardId.get());
return board.lists();
},

View file

@ -1,3 +1,5 @@
import { ReactiveCache } from '/imports/reactiveCache';
BlazeComponent.extendComponent({
addSubtask(event) {
event.preventDefault();
@ -6,7 +8,7 @@ BlazeComponent.extendComponent({
const cardId = this.currentData().cardId;
const card = Cards.findOne(cardId);
const sortIndex = -1;
const crtBoard = Boards.findOne(card.boardId);
const crtBoard = ReactiveCache.getBoard(card.boardId);
const targetBoard = crtBoard.getDefaultSubtasksBoard();
const listId = targetBoard.getDefaultSubtasksListId();

View file

@ -1,3 +1,4 @@
import { ReactiveCache } from '/imports/reactiveCache';
import { TAPi18n } from '/imports/i18n';
import { Spinner } from '/client/lib/spinner';
@ -269,7 +270,7 @@ BlazeComponent.extendComponent({
const currentBoardId = Session.get('currentBoard');
arr = [];
_.forEach(
Boards.findOne(currentBoardId)
ReactiveCache.getBoard(currentBoardId)
.customFields()
.fetch(),
function (field) {
@ -288,8 +289,8 @@ BlazeComponent.extendComponent({
getLabels() {
const currentBoardId = Session.get('currentBoard');
if (Boards.findOne(currentBoardId).labels) {
return Boards.findOne(currentBoardId).labels.filter(label => {
if (ReactiveCache.getBoard(currentBoardId).labels) {
return ReactiveCache.getBoard(currentBoardId).labels.filter(label => {
return this.labels.get().indexOf(label._id) > -1;
});
}
@ -430,7 +431,7 @@ BlazeComponent.extendComponent({
this.boardId = Session.get('currentBoard');
// In order to get current board info
subManager.subscribe('board', this.boardId, false);
this.board = Boards.findOne(this.boardId);
this.board = ReactiveCache.getBoard(this.boardId);
// List where to insert card
const list = $(Popup._getTopStack().openerElement).closest('.js-list');
this.listId = Blaze.getData(list[0])._id;
@ -589,7 +590,6 @@ BlazeComponent.extendComponent({
this.isBoardTemplateSearch;
let board = {};
if (this.isTemplateSearch) {
//board = Boards.findOne((Meteor.user().profile || {}).templatesBoardId);
board._id = (Meteor.user().profile || {}).templatesBoardId;
} else {
// Prefetch first non-current board id
@ -651,7 +651,7 @@ BlazeComponent.extendComponent({
if (!this.selectedBoardId) {
return [];
}
const board = Boards.findOne(this.selectedBoardId.get());
const board = ReactiveCache.getBoard(this.selectedBoardId.get());
if (!this.isTemplateSearch || this.isCardTemplateSearch) {
return board.searchCards(this.term.get(), false);
} else if (this.isListTemplateSearch) {
@ -713,7 +713,7 @@ BlazeComponent.extendComponent({
element.type = 'list';
_id = element.copy(this.boardId, this.swimlaneId);
} else if (this.isSwimlaneTemplateSearch) {
element.sort = Boards.findOne(this.boardId)
element.sort = ReactiveCache.getBoard(this.boardId)
.swimlanes()
.count();
element.type = 'swimlane';

View file

@ -1,3 +1,4 @@
import { ReactiveCache } from '/imports/reactiveCache';
import Attachments, { fileStoreStrategyFactory } from '/models/attachments';
const filesize = require('filesize');
@ -61,14 +62,14 @@ BlazeComponent.extendComponent({
return _version;
});
});
const board = Boards.findOne(boardId);
const board = ReactiveCache.getBoard(boardId);
board.attachments = boardAttachments;
return board;
})
return ret;
},
getBoardData(boardid) {
const ret = Boards.findOne(boardId);
const ret = ReactiveCache.getBoard(boardId);
return ret;
},
events() {

View file

@ -1,3 +1,4 @@
import { ReactiveCache } from '/imports/reactiveCache';
import { TAPi18n } from '/imports/i18n';
Sidebar = null;
@ -284,7 +285,7 @@ Template.memberPopup.events({
Cards.find({ boardId, assignees: memberId }).forEach(card => {
card.unassignAssignee(memberId);
});
Boards.findOne(boardId).removeMember(memberId);
ReactiveCache.getBoard(boardId).removeMember(memberId);
Popup.back();
}),
'click .js-leave-member': Popup.afterConfirm('leaveBoard', () => {