Skip to content

Duplicate action: possible performance issue #14992

Description

@ecomunicare

Bug description

We recently encountered a performance issue while using the entry duplication feature.
In our project—a Statamic v5.x multisite—the action to duplicate an entry in a collection of about 1,000 entries (per site) consistently resulted in a 504 Gateway Timeout.
Could this be related in some way to the recursive function that assigns a unique slug and a title to the newly duplicated entry?

protected function generateTitleAndSlug(Entry $entry, $attempt = 1)
{
    $title = $entry->value('title');
    $slug = $entry->slug();
    $suffix = ' (' . __('Duplicated') . ')';

    if ($attempt == 1) {
        $title = $title . $suffix;
    }

    if ($attempt !== 1) {
        if (! Str::contains($title, $suffix)) {
            $title .= $suffix;
        }

        $title .= ' (' . $attempt . ')';
    }

    $slug .= '-' . $attempt;

    // If the slug we've just built already exists, we'll try again, recursively.
    if ($entry->collection()->queryEntries()->where('locale', $entry->locale())->where('slug', $slug)->count()) {
        [$title, $slug] = $this->generateTitleAndSlug($entry, $attempt + 1);
    }

    return [$title, $slug];
}

Has anyone else encountered this same problem or something very similar?
Or am I missing something?

How to reproduce

  1. Statamic v5.x, Multisite (5 sites configured).
  2. A collection with a non-trivial number of entries per site (~1000+) and reasonably heavy per-entry content (Bard/Replicator fields, relationships, etc.).
  3. Attempt to duplicate any entry in that collection via the CP "Duplicate" action.

Logs

Environment

Environment
Application Name: gri.media
Laravel Version: 12.63.0
PHP Version: 8.4.23
Composer Version: 2.10.1
Environment: local
Debug Mode: ENABLED
URL: gri-media.test
Maintenance Mode: OFF
Timezone: Europe/Rome
Locale: it

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

Drivers
Broadcasting: reverb
Cache: redis
Database: sqlite
Logs: stack / single
Mail: smtp
Queue: redis
Session: file

Storage
public/storage: NOT LINKED

Locales
Installed: ar, az, cs, da, de, de_CH, en, es, fa, fr, hu, id, it, ja, ms, nb, nl, pl, pt, pt_BR, ru, sl, sv, tr, uk, vi, zh_CN, zh_TW
LaravelLang\Actions\Plugin: 1.13.2
LaravelLang\Attributes\Plugin: 2.16.4
LaravelLang\HttpStatuses\Plugin: 3.13.2
LaravelLang\Lang\Plugin: 15.32.0
LaravelLang\MoonShine\Plugin: INCORRECT
LaravelLang\StarterKits\Plugin: 1.16.0
Locales Version: 2.11.0
Protected: en, it
Publisher Version: 16.8.0

Statamic
Addons: 23
Sites: 5 (gri.media, Il Bernina, Il Grigione Italiano, Il Moesano, La Bregaglia)
Stache Watcher: Disabled
Static Caching: Disabled
Version: 5.74.3 PRO

Statamic Addons
aerni/social-links: 3.3.0
aryehraber/statamic-captcha: 1.17.0
daun/statamic-placeholders: 3.1.1
doefom/currency-fieldtype: 1.4.1
dryven/faviconator: 1.3.1
ecomunicare/documentation: 1.1.2
ecomunicare/flash-news: 1.0.5
ecomunicare/infomaniak-vod: 1.0.6
ecomunicare/keystone-ats-news-feed: 1.0.4
ecomunicare/news-sharing: 1.0.6
ecomunicare/podcast-importer: 1.0.1
ecomunicare/trash-bin: 1.5.2
emplify-software/statamic-cookie-dialog: 2.0.5
jacksleight/statamic-bard-mutator: 3.0.5
justbetter/statamic-partytown: 0.0.2
mitydigital/sitemapamic: 3.5.0
statamic/collaboration: 1.0.1
statamic/importer: 1.9.0
statamic/seo-pro: 6.11.8
stillat/meerkat: 3.3.0
stillat/relationships: 2.4.0
swiftmade/statamic-clear-assets: 3.4.0
tfd/statamic-aida: 2.2.0

Installation

Fresh statamic/statamic site via CLI

Additional details

Statamic runs in flat file mode.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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