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.

Comments

rp7 created an issue. See original summary.

rp7’s picture

Status: Active » Needs review
StatusFileSize
new8.71 KB

Here'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.

berdir’s picture

Priority: Minor » Normal

A 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.

drush core-cli
> $context = [];
> \Drupal\entity_usage\EntityUsageQueueBatchManager::queueSourcesBatchWorker('commerce_product', 10000, $context);
> $context = [];
> \Drupal\entity_usage\EntityUsageQueueBatchManager::queueSourcesBatchWorker('commerce_product_variation', 10000, $context);

(make sure to reset $context like in this example)

  • marcoscano committed cf6e9f56 on 8.x-2.x authored by rp7
    Issue #3325964 by rp7, Berdir, marcoscano: Provide option to not remove...
marcoscano’s picture

Status: Needs review » Fixed

Thanks 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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.