Problem/Motivation
When changing certain entity usage configuration (such as tracking plugins and target/source entity types) you need to re-create all the entity usage statistics (through the Drush command or /admin/config/entity-usage/batch-update).
I'm working on a project that has a lot of content, with a lot of references. This results in a ton of entity usage records, which takes several hours at best to recreate. The recreation process removes all entity usage records and because of this, there's a time-frame where entity usage info displayed to our editors (or even used by some of our custom subsystems) is empty or incomplete.
Proposed resolution
When you, for example, enable an extra tracker plugin, there's no reason for deleting everything. Therefor I was wondering if the Drush command could provide an option to skip deleting all the entity usage records.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | entity_usage-rebuild_keep_records-3325964-2.patch | 8.71 KB | rp7 |
Comments
Comment #2
rp7 commentedHere's a proposal.
The patch attached adds an extra option to the Drush command:
--keep-existing-records.By providing this option, the existing entity usage records are not removed.
Comment #3
berdirA second thing that would be very useful is being able to limit for which entity types you want to rebuild. Sometimes you enable a new source type on a site that has tends or hundreds of thousands of entities, but you're not interested in rebuilding that.
I found a workaround for that by manually calling \Drupal\entity_usage\EntityUsageQueueBatchManager::queueSourcesBatchWorker(), since the new entity types in my case just had very few entries I didn't even need to bother with batch, but you might need to do that. An option could just be passed in and if present, override the setting.
(make sure to reset $context like in this example)
Comment #5
marcoscanoThanks all. Let's get this in for now, and work on allowing to skip certain entity types in a follow-up. Opened #3348160: Allow to skip certain entity types when regenerating all statistics for that.