Optimized some slow parts of the engine.

Last low hanging fruit: parsing is slow, cache parsed calculations
This commit is contained in:
Stefan Zermatten
2021-09-29 15:54:14 +02:00
parent cb10b53a10
commit cb1fd38df3
21 changed files with 151 additions and 96 deletions

View File

@@ -1,3 +1,30 @@
import SimpleSchema from 'simpl-schema';
SimpleSchema.extendOptions(['parseLevel']);
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');