"astrotomic/laravel-translatable" n+1 queries
I've got a package issue which is composer required by twill.
800+ queries on a model only getting one locale at a time based on the /en/ suffix. I have checked and this is the only item showing up in debug tab generating this.
When i switch models to call directly from database without twill the amount of queries returned is 32 - and this is getting 388 record items on a foreach loop.
Culprit line: /vendor/astrotomic/laravel-translatable/src/Translatable/Translatable.php:161
Has anyone experienced this when calling any Twill models and managed to solve the amount of queries in this package?
6 Replies
hi @M can you clarify what you mean by calling directly without Twill? What query exactly? And what method do you use in Twill to retrieve the models?
With Twill models the model for lessons looks like this
And this is my test calling directly without twill dependencies:
this page same page also calls years, courses, lessons and twill related but dont think this matters towards the problem
yeah I definitely got that part, but I want to know how you are calling these 2 models, not the models themselves
which code is triggering the queries you are observing
In the case of the lessons it is the following:
I mean, I'm not sure what you're identifying here, your non twill model doesn't have any of that complexity. And the problem is probably not this query, but rather that you are probably triggering some lazy loading on the retrived lessons when rendering
the query you put together seems well optimized, so it's not that one directly triggering 800+ queries right?
I've tested it one by one on all of the years, courses and lessons they all produce the same problem but because theres only 6 years theres less of the same query showing up, hence ive provided the lessons which there is 388 records returned which go into the $lessons[] and they look like this on the debugger - it might be a me issue, but as you say it is fine then must be something else: