Jelajahi Sumber

Move every Boards.findOne(idOrFirstObjectSelector, options) to the ReactiveCache

Martin Filser 2 tahun lalu
induk
melakukan
2c92524cf4

+ 1 - 1
client/components/sidebar/sidebar.js

@@ -619,7 +619,7 @@ function draggableMembersLabelsWidgets() {
     const currentBoardId = Tracker.nonreactive(() => {
       return Session.get('currentBoard');
     });
-    Boards.findOne(currentBoardId, {
+    ReactiveCache.getBoard(currentBoardId, {
       fields: {
         members: 1,
         labels: 1,

+ 5 - 5
models/boards.js

@@ -1689,7 +1689,7 @@ if (Meteor.isServer) {
   Meteor.methods({
     getBackgroundImageURL(boardId) {
       check(boardId, String);
-      return Boards.findOne({ boardId: boardId }, {}, { backgroundImageUrl: 1 });
+      return ReactiveCache.getBoard(boardId, {}, { backgroundImageUrl: 1 });
     },
     quitBoard(boardId) {
       check(boardId, String);
@@ -1781,7 +1781,7 @@ if (Meteor.isServer) {
 
 // Insert new board at last position in sort order.
 Boards.before.insert((userId, doc) => {
-  const lastBoard = Boards.findOne(
+  const lastBoard = ReactiveCache.getBoard(
     { sort: { $exists: true } },
     { sort: { sort: -1 } },
   );
@@ -2061,7 +2061,7 @@ if (Meteor.isServer) {
 
       JsonRoutes.sendResult(res, {
         code: 200,
-        data: Boards.findOne({ _id: paramBoardId }),
+        data: ReactiveCache.getBoard(paramBoardId),
       });
     } catch (error) {
       JsonRoutes.sendResult(res, {
@@ -2178,7 +2178,7 @@ if (Meteor.isServer) {
     Authentication.checkBoardAccess(req.userId, id);
     try {
       if (req.body.hasOwnProperty('label')) {
-        const board = Boards.findOne({ _id: id });
+        const board = ReactiveCache.getBoard(id);
         const color = req.body.label.color;
         const name = req.body.label.name;
         const labelId = Random.id(6);
@@ -2225,7 +2225,7 @@ if (Meteor.isServer) {
       const boardId = req.params.boardId;
       const memberId = req.params.memberId;
       const { isAdmin, isNoComments, isCommentOnly, isWorker } = req.body;
-      const board = Boards.findOne({ _id: boardId });
+      const board = ReactiveCache.getBoard(boardId);
       function isTrue(data) {
         try {
           return data.toLowerCase() === 'true';

+ 3 - 2
models/server/ExporterCardPDF.js

@@ -1,3 +1,4 @@
+import { ReactiveCache } from '/imports/reactiveCache';
 // exporter maybe is broken since Gridfs introduced, add fs and path
 import { createWorkbook } from './createWorkbook';
 
@@ -33,7 +34,7 @@ class ExporterCardPDF {
         };
         _.extend(
           result,
-          Boards.findOne(this._boardId, {
+          ReactiveCache.getBoard(this._boardId, {
             fields: {
               stars: 0,
             },
@@ -621,7 +622,7 @@ class ExporterCardPDF {
   }
 
   canExport(user) {
-    const board = Boards.findOne(this._boardId);
+    const board = ReactiveCache.getBoard(this._boardId);
     return board && board.isVisibleBy(user);
   }
 }

+ 3 - 2
models/server/ExporterExcel.js

@@ -1,3 +1,4 @@
+import { ReactiveCache } from '/imports/reactiveCache';
 import moment from 'moment/min/moment-with-locales';
 import { TAPi18n } from '/imports/i18n';
 import { createWorkbook } from './createWorkbook';
@@ -35,7 +36,7 @@ class ExporterExcel {
     };
     _.extend(
       result,
-      Boards.findOne(this._boardId, {
+      ReactiveCache.getBoard(this._boardId, {
         fields: {
           stars: 0,
         },
@@ -886,7 +887,7 @@ class ExporterExcel {
   }
 
   canExport(user) {
-    const board = Boards.findOne(this._boardId);
+    const board = ReactiveCache.getBoard(this._boardId);
     return board && board.isVisibleBy(user);
   }
 }

+ 1 - 1
models/users.js

@@ -899,7 +899,7 @@ Users.helpers({
   },
 
   getTemplatesBoardSlug() {
-    //return (Boards.findOne((this.profile || {}).templatesBoardId) || {}).slug;
+    //return (ReactiveCache.getBoard((this.profile || {}).templatesBoardId) || {}).slug;
     return 'templates';
   },
 

+ 2 - 2
sandstorm.js

@@ -250,7 +250,7 @@ if (isSandstorm && Meteor.isServer) {
       isWorker,
     };
 
-    const boardMembers = Boards.findOne(sandstormBoard._id).members;
+    const boardMembers = ReactiveCache.getBoard(sandstormBoard._id).members;
     const memberIndex = _.pluck(boardMembers, 'userId').indexOf(userId);
 
     let modifier;
@@ -288,7 +288,7 @@ if (isSandstorm && Meteor.isServer) {
   // called, the user is inserted into the database but not connected. So
   // despite the appearances `userId` is null in this block.
   Users.after.insert((userId, doc) => {
-    if (!Boards.findOne(sandstormBoard._id)) {
+    if (!ReactiveCache.getBoard(sandstormBoard._id)) {
       Boards.insert(sandstormBoard, { validate: false });
       Swimlanes.insert({
         title: 'Default',