Skip to content

Add saveQuietly to CollectionTrees #1466

Description

@CapitaineToinon

Right, a lot of statamic entities have a saveQuitly option that allows saving without firing Statamic events, such as EntrySaved, EntryCreated, etc. This can be very useful when a doing bulk creation of entries programmatically while also having a queue setup, as disabling the events to and then run whatever was hooked manually can be way faster than creating thousands of elements in the queue.

However, this is currently not possible with CollectionTree. Indeed, when updating a collection tree, the event CollectionTreeSaved will be fired, which itself triggers UpdateStructuredEntryUris and UpdateStructuredEntryOrderAndParent, when it would be better to disable the events and then manually call Entry::updateUris(Collection::find("pages")); to update the uris at once.

Right now, the only way I found the disable the event is to mock it. Here I am:

  • deleting all entries from the database
  • importing all pages again (fresh markdown from an old repo), about 300 pages
  • updating the tree as some pages are parents to others
  • updating meilisearch all at once at the end.
        Event::fakeFor(function () {
            $this->truncate();

            PageSection::withoutSyncingToSearch(function () {
                $this->createHomepage();
                $this->importPageImages();
                $this->importGames();
                $this->importPages();
                $this->updateGamePages();
                $this->updatePageSections();
            });
        }, [CollectionTreeSaved::class]);

        $this->updateEntryUris();

        spin(fn() => Artisan::call('scout:import', ['model' => PageSection::class]), 'Indexing page sections');

The core problem is here where I'm updating the parent/child relationship but can't call saveQuietly as it does not exists:

                $entry->afterSave(function ($entry) use ($parent) {
                    $structure = $entry->collection()->structure()->in($entry->locale());

                    if ($parent === null) {
                        $structure->append($entry);
                    } else {
                        $structure->appendTo($parent->id(), $entry->id());
                    }

                    $structure->save(); // <- can't do that quitely
                });

I am wiling to contribute this feature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions