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

[5.x] Cache FieldtypeRepository::find() calls to a property #9643

Merged
merged 14 commits into from
Apr 3, 2024
Merged

[5.x] Cache FieldtypeRepository::find() calls to a property #9643

merged 14 commits into from
Apr 3, 2024

Conversation

JohnathonKoster
Copy link
Contributor

This PR caches the results of return FieldtypeRepository::find($this->type()); within Field::fieldtype() to reduce the number of calls made to the underlying repository.

Test adjustments due to cloned instance no longer tracking with mocked `$fieldtype =`
@JohnathonKoster JohnathonKoster mentioned this pull request Mar 3, 2024
37 tasks
@jasonvarga jasonvarga changed the title [5.x] Cache Field::fieldtype() calls behind Blink [5.x] Cache FieldtypeRepository::find() calls to a property Apr 3, 2024
@jasonvarga
Copy link
Member

jasonvarga commented Apr 3, 2024

I changed this so that it caches fieldtype instances onto the FieldtypeRepository. This cleaned it up quite a bit.

I believe the bigger offender was that FieldtypeRepository::find() would re-resolve and new up the fieldtype instance every time.

Now, yes, FieldtypeRepository::find() is still called more often than what you originally did, but the overhead is far less. Since it's a facade, it only resolves the repository out of the container once. Probably about the same or better as resolving Blink over and over. Plus now the fieldtype no longer gets newed up through the container over and over.

Also, any other places that use FieldtypeRepository::find() will benefit.

...But I have some broken tests so clearly I need to sort some things out.

@jasonvarga jasonvarga merged commit eee58bb into statamic:master Apr 3, 2024
16 checks passed
@jasonvarga jasonvarga deleted the cache-fieldtype-calls branch April 3, 2024 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants