Move ReactiveCache to imports

- so it's available for the Server too
This commit is contained in:
Martin Filser 2022-12-09 16:41:59 +01:00
parent 47427f89b0
commit 16130b3f73
3 changed files with 46 additions and 14 deletions

View file

@ -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;
}
}

45
imports/reactiveCache.js Normal file
View file

@ -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 };

View file

@ -1,3 +1,4 @@
import { ReactiveCache } from '/imports/reactiveCache';
import moment from 'moment/min/moment-with-locales';
import {
ALLOWED_COLORS,