Skip to content

Asset browser becomes extremely slow with tens of thousands of assets #443

@mfischer-wfm

Description

@mfischer-wfm

Bug description

We use the local driver for our assets. The metadata of the images are in the asstes_meta table of the database and we have also executed the command php please eloquent:sync-assets.

With tens of thousands of assets (~ 300.000), the asset browser in the cp becomes extremely slow. Every single interaction with the assets (open asset browser, open asset to edit meta data, assign asset to a collection entry) takes 10 - 20 seconds.

Image

With the help of xdebug, we were able to narrow down the problem to the Flysystem\LocalFilesystemAdapter.

The adapter's listContents method loops through the entire content of the specified folder/asset container - even if only 25 items per page are to be displayed in the cp.

If we simply insert a return; in the foreach loop of the listContents method (foreach ($iterator as $fileInfo) {}) after 25 iterations, we get the desired results in ~200 ms instead of ~10 seconds.

Update: There is a similar problem in the listContents method in the Flysystem\AwsS3V3Adapter. Without a limit, the method loops over all assets in the specified bucket.

How to reproduce

  • create asset container with local disk

  • upload or import tens of thousands of files into the local directory

Logs

Environment

Environment
Application Name: elektroniknet
Laravel Version: 11.44.2
PHP Version: 8.3.17
Composer Version: 2.8.3
Environment: local
Debug Mode: ENABLED
URL: 127.0.0.1:8000
Maintenance Mode: OFF
Timezone: UTC
Locale: de

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

Drivers
Broadcasting: log
Cache: redis
Database: mariadb
Logs: stack / single
Mail: log
Queue: sync
Session: redis

Statamic
Addons: 6
Sites: 1
Stache Watcher: Disabled
Static Caching: Disabled
Version: 5.56.0 PRO

Statamic Addons
alt-design/alt-seo: 1.3.0
daun/statamic-loupe: 1.6.0
jacksleight/statamic-bonus-routes: 0.3.2
statamic-rad-pack/meilisearch: 3.4.0
statamic-rad-pack/runway: 8.5.0
statamic/eloquent-driver: 4.23.0

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

Installation

Fresh statamic/statamic site via CLI

Additional details

filesystems.php

    'disks' => [

        'assets' => [
            'driver' => 'local',
            'serve' => true,
            'root' => public_path('assets/images'),
            'url' => env('CDN_URL_ASSETS'),
            'disable_asserts' => true,
            'visibility' => 'public',
            'throw' => false,
        ],

        'svg' => [
            'driver' => 'local',
            'root' => public_path('assets/svg'),
            'url' => '/assets/svg',
            'visibility' => 'public',
            'throw' => false,
        ],

    ],

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions