statamic / eloquent-driver

Provides support for storing your Statamic data in a database, rather than flat files.
https://statamic.dev/tips/storing-content-in-a-database
MIT License
104 stars 74 forks source link

N+1 Query Issue on Production - Statamic Version 5.27.0 #367

Open brew-cristian opened 2 days ago

brew-cristian commented 2 days ago

Bug description

Hello, We've recently deployed our website to production and have noticed an outgoing Sentry error related to N+1 queries. This issue seems to affect multiple pages, causing performance concerns.

How to reproduce


Issue Details:

Query Details:

  1. SQL Query:

    SELECT * FROM assets_meta WHERE container = ? AND path IN (?)
  2. Additional Query:

    SELECT * FROM entries WHERE collection IN (?) AND published = ? AND (json_extract(data, '$.redirect') IS NULL OR json_type(json_extract(data, '$.redirect')) = 'NULL') AND id IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ORDER BY json_unquote(json_extract(data, '$.title')) ASC

Logs

No logs are provided in the app, just the Sentry ones above.

Environment

Environment
Laravel Version: 11.27.2
PHP Version: 8.3.7
Composer Version: 2.7.6
Maintenance Mode: OFF
Timezone: America/New_York
Locale: en

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: NOT CACHED

Drivers
Broadcasting: log
Cache: file
Database: mysql
Logs: stack / single
Mail: smtp
Queue: redis
Session: file

Livewire
Livewire: v3.5.10

Sentry
Enabled: MISSING DSN 
Laravel SDK Version: 4.9.0
PHP SDK Version: 4.9.0
Release: NOT SET
Sample Rate Errors: 100%
Sample Rate Performance Monitoring: NOT SET
Sample Rate Profiling: NOT SET
Send Default PII: DISABLED

Statamic
Addons: 10
Sites: 1
Stache Watcher: Enabled
Static Caching: half
Version: 5.30.0 PRO

Statamic Addons
duncanmcclean/static-cache-manager: 4.0.0
edalzell/forma: 3.0.1
jonassiewertsen/statamic-livewire: 3.8.1
marcorieser/tailwind-merge-statamic: 1.1.0
rias/statamic-data-import: 1.5.0
statamic/eloquent-driver: 4.15.2
studio1902/statamic-peak-browser-appearance: 3.5.0
studio1902/statamic-peak-seo: 8.16.0
studio1902/statamic-peak-tools: 6.3.3
xndbogdan/statamic-bard-text-color: 5.1.1

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: eloquent
Navigations: eloquent
Revisions: eloquent
Sites: file
Taxonomies: eloquent
Terms: eloquent
Tokens: file

Additional details

No response

ryanmitchell commented 2 days ago

It's not clear from your issue how those queries are related and combining to make an N+1 issue - can you detail that out. Better yet would be to provide a basic repository showing the issue.

brew-cristian commented 2 days ago

It's not clear from your issue how those queries are related and combining to make an N+1 issue - can you detail that out. Better yet would be to provide a basic repository showing the issue.

Thank you for your feedback. Unfortunately, I am unable to share the repository as it contains sensitive information and is tied to our production environment. The error captured by Sentry occurs irregularly and involves queries to the assets_meta and entries tables.