Problem/Motivation

The resource_conflict module currently passes full node entities through ConflictsEvent. This means conflict nodes are loaded before the resource_conflict.conflicts_filter event is dispatched, even when subscribers only need node IDs or might filter out all conflicts. This adds unnecessary entity loading overhead and makes it harder for subscribers to control when, or if, entities are loaded.

Proposed resolution

  • Change ConflictsEvent to carry a list of conflicting node IDs instead of an array of node entities:
    • Constructor now accepts int[] $conflictIds.
    • getConflicts() / setConflicts() are replaced with getConflictIds() / setConflictIds().
    • Docblocks updated to describe int[] of node IDs.
  • Update ResourceConflictManager::getConflicts() to:
    • Fetch conflicting node IDs via getConflictingNodeIds().
    • Dispatch ConflictsEvent with IDs only.
    • Allow subscribers to filter or replace the ID list.
    • Only load node entities with loadMultiple() after the event has finished and the final list of IDs is known.
  • Update the example event subscriber in resource_conflict.examples.inc to work with IDs:
    • Use getConflictIds() to inspect conflicts.
    • Log counts based on IDs.
    • Demonstrate filtering by keeping only the first conflict ID and calling setConflictIds().
  • Adjust the test validation subscriber to follow the new pattern:
    • Inject entity_type.manager.
    • Use getConflictIds() inside onConflictsFilter().
    • Load entities only when needed to filter by room, and then update the event with the filtered list of IDs via setConflictIds().
  • Update the README to clarify that the conflicts filter event exposes node IDs, and that subscribers can load and act on the conflicts as needed.

API changes

  • Drupal\resource_conflict\Event\ConflictsEvent:
    • Constructor now accepts int[] $conflictIds instead of an array of NodeInterface objects.
    • getConflicts() and setConflicts() are replaced by
      getConflictIds() and setConflictIds().
    • Subscribers that previously expected an array of node entities must be
      updated to use IDs and load entities themselves if needed.
  • ResourceConflictManager::getConflicts() now dispatches the
    CONFLICTS_FILTER event with IDs and loads node entities only
    after subscribers have filtered the IDs.
  • resource_conflict_test_validation test subscriber now requires
    entity_type.manager to load nodes in order to filter conflicts.
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

joelpittet created an issue. See original summary.

joelpittet’s picture

Issue summary: View changes

  • joelpittet committed 54117c7e on 2.x
    feat: #3560894 Defer loading conflict nodes by passing node IDs through...
joelpittet’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.

Status: Fixed » Closed (fixed)

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