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

This commit is contained in:
Martin Filser 2023-02-05 11:02:39 +01:00
parent 767d8e66e7
commit 6b7b464acc
4 changed files with 55 additions and 5 deletions

View file

@ -437,7 +437,7 @@ BlazeComponent.extendComponent({
for (const k in condition) {
if (!condition[k]) delete condition[k];
}
return Integrations.findOne(condition);
return ReactiveCache.getIntegration(condition);
},
onCreated() {
this.disabled = new ReactiveVar(false);

View file

@ -147,6 +147,14 @@ ReactiveCacheServer = {
const ret = ImpersonatedUsers.find(selector, options).fetch();
return ret;
},
getIntegration(idOrFirstObjectSelector, options) {
const ret = Integrations.findOne(idOrFirstObjectSelector, options);
return ret;
},
getIntegrations(selector, options) {
const ret = Integrations.find(selector, options).fetch();
return ret;
},
getCurrentSetting() {
const ret = Settings.findOne();
return ret;
@ -593,6 +601,30 @@ ReactiveCacheClient = {
const ret = this.__impersonatedUsers.get(Jsons.stringify(select));
return ret;
},
getIntegration(idOrFirstObjectSelector, options) {
const idOrFirstObjectSelect = {idOrFirstObjectSelector, options}
if (!this.__integration) {
this.__integration = new DataCache(_idOrFirstObjectSelect => {
const __select = Jsons.parse(_idOrFirstObjectSelect);
const _ret = Integrations.findOne(__select.idOrFirstObjectSelector, __select.options);
return _ret;
});
}
const ret = this.__integration.get(Jsons.stringify(idOrFirstObjectSelect));
return ret;
},
getIntegrations(selector, options) {
const select = {selector, options}
if (!this.__integrations) {
this.__integrations = new DataCache(_select => {
const __select = Jsons.parse(_select);
const _ret = Integrations.find(__select.selector, __select.options).fetch();
return _ret;
});
}
const ret = this.__integrations.get(Jsons.stringify(select));
return ret;
},
getCurrentSetting() {
if (!this.__currentSetting || !this.__currentSetting.get()) {
this.__currentSetting = new DataCache(() => {
@ -946,6 +978,24 @@ ReactiveCache = {
}
return ret;
},
getIntegration(idOrFirstObjectSelector, options) {
let ret;
if (Meteor.isServer) {
ret = ReactiveCacheServer.getIntegration(idOrFirstObjectSelector, options);
} else {
ret = ReactiveCacheClient.getIntegration(idOrFirstObjectSelector, options);
}
return ret;
},
getIntegrations(selector, options) {
let ret;
if (Meteor.isServer) {
ret = ReactiveCacheServer.getIntegrations(selector, options);
} else {
ret = ReactiveCacheClient.getIntegrations(selector, options);
}
return ret;
},
getCurrentSetting() {
let ret;
if (Meteor.isServer) {

View file

@ -177,7 +177,7 @@ if (Meteor.isServer) {
JsonRoutes.sendResult(res, {
code: 200,
data: Integrations.findOne(
data: ReactiveCache.getIntegration(
{ _id: paramIntId, boardId: paramBoardId },
{ fields: { token: 0 } },
),
@ -324,7 +324,7 @@ if (Meteor.isServer) {
JsonRoutes.sendResult(res, {
code: 200,
data: Integrations.findOne(
data: ReactiveCache.getIntegration(
{ _id: paramIntId, boardId: paramBoardId },
{ fields: { _id: 1, activities: 1 } },
),
@ -364,7 +364,7 @@ if (Meteor.isServer) {
JsonRoutes.sendResult(res, {
code: 200,
data: Integrations.findOne(
data: ReactiveCache.getIntegration(
{ _id: paramIntId, boardId: paramBoardId },
{ fields: { _id: 1, activities: 1 } },
),

View file

@ -163,7 +163,7 @@ if (Meteor.isServer) {
data: is2way ? { description, ...clonedParams } : value,
};
if (!Integrations.findOne({ url: integration.url })) return;
if (!ReactiveCache.getIntegration({ url: integration.url })) return;
const url = integration.url;