Move every Users.findOne() to the ReactiveCache

This commit is contained in:
Martin Filser 2023-01-15 01:11:16 +01:00
parent bf48d4371c
commit 6e1ef3d94a
35 changed files with 175 additions and 125 deletions

View file

@ -31,10 +31,18 @@ ReactiveCacheServer = {
const ret = CustomFields.find(selector).fetch();
return ret;
},
getUser(id) {
const ret = Users.findOne(id);
return ret;
},
getCurrentSetting() {
const ret = Settings.findOne();
return ret;
},
getCurrentUser() {
const ret = Meteor.user();
return ret;
},
}
// only the Client is reactive
@ -111,6 +119,16 @@ ReactiveCacheClient = {
const ret = this.__customFields.get(Jsons.stringify(selector));
return ret;
},
getUser(id) {
if (!this.__user) {
this.__user = new DataCache(userId => {
const _ret = Users.findOne(userId);
return _ret;
});
}
const ret = this.__user.get(id);
return ret;
},
getCurrentSetting() {
if (!this.__currentSetting || !this.__currentSetting.get()) {
this.__currentSetting = new DataCache(() => {
@ -120,6 +138,16 @@ ReactiveCacheClient = {
}
const ret = this.__currentSetting.get();
return ret;
},
getCurrentUser() {
if (!this.__currentUser || !this.__currentUser.get()) {
this.__currentUser = new DataCache(() => {
const _ret = Meteor.user();
return _ret;
});
}
const ret = this.__currentUser.get();
return ret;
}
}
@ -193,6 +221,15 @@ ReactiveCache = {
}
return ret;
},
getUser(id) {
let ret;
if (Meteor.isServer) {
ret = ReactiveCacheServer.getUser(id);
} else {
ret = ReactiveCacheClient.getUser(id);
}
return ret;
},
getCurrentSetting() {
let ret;
if (Meteor.isServer) {
@ -202,6 +239,15 @@ ReactiveCache = {
}
return ret;
},
getCurrentUser() {
let ret;
if (Meteor.isServer) {
ret = ReactiveCacheServer.getCurrentUser();
} else {
ret = ReactiveCacheClient.getCurrentUser();
}
return ret;
},
}
export { ReactiveCache };