This pull request refactors how Eloquent Relationships are augmented to improve performance and prevent as many duplicate queries, like seen in #430.
Changes include:
Instead of a HasMany/BelongsTo relationship instance being passed to the augmentation methods, we now pass an Eloquent\Collection instance.
Essentially, we're now doing $model->relationship instead of $model->relationship(). This change also lets us take advantage of eager loading for the related models.
I've refactored the augmentation methods in the BaseFieldtype to simplify it, now it only needs to accept an Eloquent\Collection or an array of IDs (in the case the fieldtype is being used on entries).
The runwayUri relationship no longer gets augmented.
There's no reason for the runwayUri relation to be augmented in the first place so it's a quick win 🚀
Previously, the {{ runway }} tag wasn't eager loading any relationships, unless you were providing the relationships to be eager loaded yourself.
Now, similar to the listing table in the CP, Runway will automatically eager load models based on the relationship fields you have configured in your resource blueprint.
Testing
On my local sandbox, I managed to reduce the number of total queries for index pages (which use the {{ runway }} tag) down from a couple hundred to 3 queries.
Then, in the demo site provided in #430, I've managed to get rid of the duplicate queries & reduce the total number of queries down to 108, which is more reasonable than a couple thousand.
This pull request refactors how Eloquent Relationships are augmented to improve performance and prevent as many duplicate queries, like seen in #430.
Changes include:
HasMany
/BelongsTo
relationship instance being passed to the augmentation methods, we now pass anEloquent\Collection
instance.$model->relationship
instead of$model->relationship()
. This change also lets us take advantage of eager loading for the related models.BaseFieldtype
to simplify it, now it only needs to accept anEloquent\Collection
or an array of IDs (in the case the fieldtype is being used on entries).runwayUri
relationship no longer gets augmented.runwayUri
relation to be augmented in the first place so it's a quick win 🚀{{ runway }}
tag wasn't eager loading any relationships, unless you were providing the relationships to be eager loaded yourself.Testing
On my local sandbox, I managed to reduce the number of total queries for index pages (which use the
{{ runway }}
tag) down from a couple hundred to 3 queries.Then, in the demo site provided in #430, I've managed to get rid of the duplicate queries & reduce the total number of queries down to 108, which is more reasonable than a couple thousand.
Closes #430.