Currently the defaultValue is always set during the execution of the constructor for each property.
When using the defaultValue function to create cryptographically strong tokens (as an example) this produces a lot of overhead on each model invocation.
One possible way to reduce this is to only set the defaultValue when it's required. Meaning on save() or property access.
Another way could be to optionally not invoke defaultValue functions in the constructor via argument, then pass this argument from all static shortform methods that create an instance (.load(), .loadMany(), .findAndLoad(), .remove()).
For now a possible work-around is to extend save() like this:
// typescript example
protected async save() {
if (!this.id) {
this.property('loginToken', (await randomBytes(128)).toString('hex'));
}
return super.save();
}
Currently the defaultValue is always set during the execution of the constructor for each property.
When using the defaultValue function to create cryptographically strong tokens (as an example) this produces a lot of overhead on each model invocation.
One possible way to reduce this is to only set the defaultValue when it's required. Meaning on save() or property access.
Another way could be to optionally not invoke defaultValue functions in the constructor via argument, then pass this argument from all static shortform methods that create an instance (.load(), .loadMany(), .findAndLoad(), .remove()).
For now a possible work-around is to extend save() like this: