eloquent-driver
eloquent-driver copied to clipboard
Duplicated Queries all the way
I have a Landingpage with 4 Entries - nothing else. A Author is linked, also a Category and Image.
The problem I am facing is that a looooot of queries are executed, and i have no clue where to fix this, include a Cache or smth. I need a hint or something - there are 158 Queries for 4 Blogposts.
158 statements were executed, 130 of which were duplicates, 28 unique.
Can you please paste the contents of php please support:details ?
Are you using an entries field type?
php please support:details
Environment
Application Name: localtest.de
Laravel Version: 10.45.1
PHP Version: 8.1.27
Composer Version: 2.5.5
Environment: debug
Debug Mode: ENABLED
URL: localtest.de.test
Maintenance Mode: OFF
Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: NOT CACHED
Drivers
Broadcasting: log
Cache: statamic
Database: mysql
Logs: stack / single
Mail: smtp
Queue: sync
Session: file
Statamic
Addons: 5
Antlers: runtime
Sites: 1
Stache Watcher: Disabled
Static Caching: Disabled
Version: 4.55.0 Solo
Statamic Addons
statamic/eloquent-driver: 3.1.2
studio1902/statamic-peak-browser-appearance: 3.3.4
studio1902/statamic-peak-commands: 4.4.0
studio1902/statamic-peak-seo: 8.2.0
studio1902/statamic-peak-tools: 4.4.2
Statamic Eloquent Driver
Asset Containers: eloquent
Assets: eloquent
Blueprints: file
Collection Trees: eloquent
Collections: eloquent
Entries: eloquent
Forms: eloquent
Global Sets: eloquent
Global Variables: eloquent
Navigation Trees: file
Navigations: file
Revisions: eloquent
Taxonomies: eloquent
Terms: eloquent
Yess the Author is a Entries Field Type.
Yep, so you're seeing the result of the queries from augmentation on the entries field type (I believe): https://github.com/statamic/cms/blob/08512240a30112a0dcf658385d404caad4d6cf0a/src/Fieldtypes/Entries.php#L329-L340
I'm hopeful some of the performance improvements coming in v5 of core will reduce the duplicate queries.
Yes for the Entries this might be true - at least the Fieltypes/Entries in in the Backtrace
However would this be the same for e.g. Assets and Taxonomies
Yes, the field types all work the same way and currently don't cache their query results.
Allrighty - thank you for the explanation. Any known workaround or just wait for Statamic5? π
Given how close v5 is I'd suggest waiting it out for the next couple of weeks.
Allrighty - thank you. Much apprechiated ππ»
Has this issue been fixed with Statamic v5? I'm still seeing hundreds of queries for each page including duplicate assets_meta queries like this one repeated 7 times:
select * from `assets_meta` where `container` = '{\"id\":\"assets\",\"title\":\"Assets\",\"handle\":\"assets\",\"disk\":\"s3\",\"blueprint\":{\"title\":\"Asset\",\"handle\":\"assets\"},\"search_index\":null,\"api_url\":null}' and `path` in ('my-filename.jpg')
-- EloquentQueryBuilder.php#58
Asset Containers: file
Assets: eloquent
No it hasnβt. How the asset field would need to be changed in core - we canβt fix it on the driver side.
@clementmas i took a quick look at Statamic5 for my project when it was released and i also still have a looot of duplicate queries. I even thought the site was slower after the upgrade π So it's currently still running on Statamic4.
Since my job is quite demanding currently I wasn't able to check if it may be a config problem on my side from the upgrade or investigate further/give more details about the problem/recreate or replicate the issue in a new Repo for the devs.
@ryanmitchell thanks for the update ππ»
I've chatted this through a bit both on the core side and the antlers side and the solution for now is to assign the value to a variable eg
{{ $my_field_cached = my_field }}
{{ $my_field_cached }}
// do stuff
{{ /$my_field_cached }}
this will ensure the parser gets and caches the value.
As its already blinking the result of max_items: 1 fields (see PR) this only is needed for fields that aren't max_items: 1