Skip to content

Nav output appears to query entire entries and any related values, when using the Eloquent driver #543

@justindantzer

Description

@justindantzer

Bug description

When outputting a nav, using the standard nav:name_here tag, it appears that all associated data to the nav entries are queried for, including related assets or relationships attached via Bard sets. This is resulting in many extra queries on all pages, depending on the size and context of your content. I would have expected that only fields needed to build the structure would be queried, such as parent relationship, url slug, title, and any custom fields included.

As an example, my site has ~20 pages, each with a few images or references to PDF files, resulting in ~100 extra queries on each page.

Edit: Current usage
{{ nav:main_navigation select="title|url" }}

How to reproduce

  • Setup Eloquent Driver
  • Setup collections to store with Eloquent
  • Create a collection with a bard field that uses sets, and include a set with an asset field
  • create a few entries, being sure to include attached assets
  • Add the collection items to a nav
  • Output the nav on a template
  • View queries issued on the page (Laravel Debugbar helped)

Logs

Environment

Environment
Laravel Version: 12.51.0
PHP Version: 8.5.2
Composer Version: 2.9.3
Environment: local
Debug Mode: ENABLED
Maintenance Mode: OFF
Locale: en

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

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

Storage
public/storage: LINKED

Nova
Authentication: ENABLED
Authentication Guard: web
Authentication User: App\Models\User
Currency: USD
Global Debounce: 0.5s
Global Search: ENABLED
Notification Center: ENABLED
Notification Polling: 7s
Pagination: simple
Password Reset: ENABLED
Password Reset Broker: null
RTL Enabled: OFF
Storage Disk: public
Theme Switcher: ENABLED
Version: 5.7.7 (Silver Surfer)

Spatie Permissions
Features Enabled: Default
Version: 6.24.1

Statamic
Addons: 5
Sites: 1
Stache Watcher: Enabled (auto)
Static Caching: Disabled
Version: 5.73.6 PRO

Statamic Addons
anakadote/statamic-recaptcha: 2.0
rias/statamic-redirect: 3.14.1
statamic-rad-pack/runway: 8.9.0
statamic/eloquent-driver: 4.36.0
statamic/seo-pro: 6.11.7

Statamic Eloquent Driver
Asset Containers: eloquent
Assets: eloquent
Blueprints: eloquent
Collection Trees: eloquent
Collections: eloquent
Entries: eloquent
Fieldsets: eloquent
Form Submissions: eloquent
Forms: eloquent
Global Sets: eloquent
Global Variables: eloquent
Navigation Trees: eloquent
Navigations: eloquent
Revisions: file
Sites: eloquent
Taxonomies: eloquent
Terms: eloquent
Tokens: eloquent

Additional details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions