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

  1. Enable term_merge_manager + pathauto with a pattern on the vocabulary.
  2. Create a rule merging term "A" into existing term "B".
  3. 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}.

Command icon 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

mfrosch created an issue. See original summary.

  • mfrosch committed eee9d220 on 2.x
    fix: #3612961 Automated merges append a duplicate URL alias to the...
mfrosch’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

mfrosch’s picture

Status: Fixed » Closed (fixed)