Files
DiceCloud/app/imports/api/simpleSchemaConfig.js
Stefan Zermatten cb1fd38df3 Optimized some slow parts of the engine.
Last low hanging fruit: parsing is slow, cache parsed calculations
2021-09-29 15:54:14 +02:00

31 lines
911 B
JavaScript

import SimpleSchema from 'simpl-schema';
SimpleSchema.extendOptions([
'parseLevel',
'removeBeforeCompute',
'inlineCalculationField',
'computedField',
]);
// Store a quick way of referencing keys that have specific tags === true
function storeTaggedKeys(tag, fnName){
SimpleSchema.prototype[fnName] = function(){
if (!this['_' + fnName]){
this['_' + fnName] = [];
for (const key in this._schema){
if (this._schema[key][tag]){
this['_' + fnName].push(key);
}
}
}
return this['_' + fnName];
}
}
// Keys that should be deleted at the start of a computation
storeTaggedKeys('removeBeforeCompute', 'removeBeforeComputeFields');
// Keys that represent inline calculation objects
storeTaggedKeys('inlineCalculationField', 'inlineCalculationFields');
// Keys that represent computed field objects
storeTaggedKeys('computedField', 'computedFields');