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.
Right, a lot of statamic entities have a
saveQuitlyoption 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
CollectionTreeSavedwill be fired, which itself triggersUpdateStructuredEntryUrisandUpdateStructuredEntryOrderAndParent, when it would be better to disable the events and then manually callEntry::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:
The core problem is here where I'm updating the parent/child relationship but can't call saveQuietly as it does not exists:
I am wiling to contribute this feature.