Problem/Motivation

While investigating performance issues on a large site using the backlinks_index module, I noticed that the batch process queries all nodes regardless of the allowed bundles configured in the module settings. This occurs in two places:

On large-scale sites, this results in heavy and unnecessary database load since all nodes are being fetched, even if only specific bundles are configured to be indexed.

In addition, the truncateBacklinks() method updates all entries in the node_field_data table instead of limiting the update to rows where backlinks = 1. This can lead to unnecessary write operations on the entire table.

Proposed resolution

Batch processing improvement:

Use the $sandbox to pass through the filtered node IDs (based on allowed bundles) and iterate through those. This avoids querying the entire node table during every batch step.

Truncate optimization:

Before running the update, check if there are rows with backlinks = 1. Add a condition to the query so it only updates those specific rows, minimizing the performance impact.

CommentFileSizeAuthor
#2 3543687-2.patch3.13 KBaurora.luzzardi
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

aluzzardi created an issue. See original summary.

aurora.luzzardi’s picture

StatusFileSize
new3.13 KB

Here a patch with the proposed solution for version 1.1.2

aurora.luzzardi’s picture

Status: Active » Needs work

matej.lehotsky made their first commit to this issue’s fork.

  • matej.lehotsky committed 647e256f on 1.1.x
    Issue #3543687 by aluzzardi: Improve performance by filtering allowed...
matej.lehotsky’s picture

Status: Needs work » Reviewed & tested by the community
matej.lehotsky’s picture

Status: Reviewed & tested by the community » 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.

matej.lehotsky’s picture

Status: Fixed » Closed (fixed)