diff --git a/client/lib/reactiveCache.js b/client/lib/reactiveCache.js deleted file mode 100644 index f72bfa3c1..000000000 --- a/client/lib/reactiveCache.js +++ /dev/null @@ -1,14 +0,0 @@ -import { DataCache } from 'meteor-reactive-cache'; - -// global Reactive Cache class to avoid big overhead while searching for the same data often again -ReactiveCache = { - getBoard(id) { - if (!this.__board) { - this.__board = new DataCache(boardId => { - return Boards.findOne(boardId); - }); - } - const ret = this.__board.get(id); - return ret; - } -} diff --git a/imports/reactiveCache.js b/imports/reactiveCache.js new file mode 100644 index 000000000..7aa13140a --- /dev/null +++ b/imports/reactiveCache.js @@ -0,0 +1,45 @@ +import { DataCache } from 'meteor-reactive-cache'; + +// Server isn't reactive, so search for the data always. +ReactiveCacheServer = { + getBoard(id) { + const ret = Boards.findOne(id); + return ret; + }, +} + +// only the Client is reactive +// saving the result has a big advantage if the query is big and often searched for the same data again and again +// if the data is changed in the client, the data is saved to the server and depending code is reactive called again +ReactiveCacheClient = { + getBoard(id) { + if (!this.__board) { + this.__board = new DataCache(boardId => { + const _ret = Boards.findOne(boardId); + return _ret; + }); + } + const ret = this.__board.get(id); + return ret; + } +} + +// global Reactive Cache class to avoid big overhead while searching for the same data often again +// This class calls 2 implementation, for server and client code +// +// having this class here has several advantages: +// - The Programmer hasn't to care about in which context he call's this class +// - having all queries together in 1 class to make it possible to see which queries in Wekan happens, e.g. with console.log +ReactiveCache = { + getBoard(id) { + let ret; + if (Meteor.isServer) { + ret = ReactiveCacheServer.getBoard(id); + } else { + ret = ReactiveCacheClient.getBoard(id); + } + return ret; + }, +} + +export { ReactiveCache }; diff --git a/models/cards.js b/models/cards.js index dae7df02e..70ebd5178 100644 --- a/models/cards.js +++ b/models/cards.js @@ -1,3 +1,4 @@ +import { ReactiveCache } from '/imports/reactiveCache'; import moment from 'moment/min/moment-with-locales'; import { ALLOWED_COLORS,