Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement lazy joins and Lazy fields #118

Open
romaninsh opened this issue Aug 25, 2016 · 5 comments
Open

Implement lazy joins and Lazy fields #118

romaninsh opened this issue Aug 25, 2016 · 5 comments

Comments

@romaninsh
Copy link
Member

romaninsh commented Aug 25, 2016

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
@romaninsh romaninsh added this to the 1.2.0 milestone Sep 19, 2016
@romaninsh romaninsh changed the title Implement optional joins Implement lazy joins and Lazy fields Dec 5, 2016
@romaninsh
Copy link
Member Author

see #208,.

@romaninsh
Copy link
Member Author

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.

@romaninsh
Copy link
Member Author

Use case: password field could be lazy, because we don't like loading passwords.

@mvorisek
Copy link
Member

very simillar feature request: #319

@mvorisek
Copy link
Member

related with #1093

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants