Problem/Motivation
When a stored merge rule matches, taxonomyTermPresave() rewrites
the incoming term onto the existing target term. The rewritten entity carries no
existing Pathauto state, so Pathauto generates and appends a new URL
alias to the target term on every merge. Over many automated merges this
accumulates huge numbers of duplicate {path_alias} rows, which slows
alias lookups and, on a decoupled front end, caused page-generation timeouts and
cached 404s.
Steps to reproduce
- Enable term_merge_manager + pathauto with a pattern on the vocabulary.
- Create a rule merging term "A" into existing term "B".
- Trigger it repeatedly; then:
SELECT alias, path, COUNT(*) FROM path_alias GROUP BY alias, path HAVING COUNT(*) > 1;
— the target's alias count grows by one per merge.
Proposed resolution
After the term is rewritten to the target in the presave handler, skip Pathauto
for that save (guarded by moduleExists('pathauto'), so Pathauto stays
optional):
if (\Drupal::moduleHandler()->moduleExists('pathauto')) { $entity->get('path')->pathauto = \Drupal\pathauto\PathautoState::SKIP; }
Add hook_update_N to clean up already-duplicated aliases: keep the
lowest id per (path, alias, langcode) and delete the rest, batched via the update
sandbox (portable, resumable — no MySQL-only DELETE … LIMIT).
Remaining tasks
- Review MR (patch + Kernel test included).
API changes
None. Behavioural change only: an automated merge no longer triggers Pathauto
alias (re)generation on the target term.
Data model changes
No schema changes. New term_merge_manager.install adds
term_merge_manager_update_9001(), which removes duplicate rows from
{path_alias}.
Issue fork term_merge_manager-3612961
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
mfrosch commentedComment #6
mfrosch commented