data
data copied to clipboard
Implement lazy joins and Lazy fields
Lazy Fields and Lazy Joins are those optional fields that will not be loaded unless requested. The logic should be like this:
- without onlyFields() - load all fields except lazy
- with onlyFields() - load requested fields and system fields
Adding a lazyJoin will make it's field lazy too. If you have not requested any of the "lazy" fields from the join, then join won't be performed either.
As suggested on reddit - we should make our 'leftJoin' optional.
adding leftJoin does not impact the scope of the model. So if no fields have been selected (through onlyFields) from the joined table, then there is no need to join it. This can be a good optimisation if we:
- remove "system" from our_field field.
- add field into onlyFields if any fields required by joins are requested
- add our_field if join requires it and if it's located in a join, add that one also
- do so recursively
see #208,.
Suggested syntax:
$model->addExpression('bleh', ['..complex formula', 'lazy'=>true]);
$model->addField('blob', ['lazy'=>true']);
Unlike system
property which makes fields selected by default (even if onlyFields in effect) lazy will avoid selecting fields unless they are specifically requested by onlyFields.
A difference to onlyFields would be if lazy field is accessed:
$model->load(1);
echo $model['blob'];
Then model would specifically load the field. In most cases this is a reasonable trade off for a lazy field. This mechanic will NOT work for fields that are omitted by onlyFields, because otherwise this can cause sigificant application slow-down when accessing a field, which ought to be system.
Use case: password field could be lazy, because we don't like loading passwords.
very simillar feature request: https://github.com/atk4/data/issues/319
related with https://github.com/atk4/data/issues/1093