Skip to content

Conversation

@jjroelofs
Copy link
Contributor

Summary

  • Add ContentIntelCollectorInterface for better architecture
  • Add logging for silent exception handling in ContentTranslationPlugin
  • Optimize batch command with bulk entity loading

Linked Issues

Changes

ContentIntelCollectorInterface (#2)

  • New interface defining the service contract
  • ContentIntelCollector now implements the interface
  • Added loadEntities() method for bulk entity loading

ContentTranslationPlugin logging (#3)

  • Injected logger service
  • Logs warnings when translation metadata fetch fails
  • Adds metadata_error field to output for debugging

Batch command optimization (#4)

  • Uses loadEntities() for bulk loading instead of individual loads
  • Reduces N+1 queries to single loadMultiple() call
  • Improves performance for large batch operations

Test Plan

  • Run drush ci:plugins to verify module loads correctly
  • Run drush ci:batch node --bundle=article --limit=10 to test batch optimization
  • Verify interface can be type-hinted in dependent code

Jurriaan Roelofs added 3 commits January 28, 2026 10:49
Fix #2: Add ContentIntelCollectorInterface
- Create interface defining the service contract
- Update ContentIntelCollector to implement the interface
- Add loadEntities() method for bulk entity loading

Fix #3: Add logging for silent exception in ContentTranslationPlugin
- Inject logger service
- Log warnings when translation metadata fetch fails
- Add metadata_error field to output for debugging

Fix #4: Optimize batch command with loadMultiple()
- Use loadEntities() for bulk loading instead of individual loads
- Reduces N+1 queries to single loadMultiple() call
- Improves performance for large batch operations
- Install statistics contrib module in drupal-check script
- Add PHPStan config to ignore optional statistics module errors
- Fix type safety: add ContentEntityInterface check in listEntities()
- Fix DI: inject date.formatter service in StatisticsPlugin
Copy link
Contributor Author

@jjroelofs jjroelofs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review: Address multiple improvement issues (#2, #3, #4)

This PR cleanly addresses three issues with well-structured code. Looks good to merge.


Issue #2: Interface for ContentIntelCollector ✅

  • Complete interface with all public methods documented
  • Proper PHPDoc with return type descriptions
  • loadEntities() method correctly added to interface

Issue #3: Silent Exception Handling ✅

  • Logger properly injected via container factory
  • Uses appropriate warning level
  • Adds metadata_error field to output - nice touch for debugging

Issue #4: Batch Optimization ✅

  • loadMultiple() used correctly for bulk loading
  • Empty array guard prevents unnecessary DB calls
  • Both code paths optimized (IDs provided vs listing)

Bonus Fixes 👍

  • Fixed static \Drupal::service('date.formatter') in StatisticsPlugin
  • Added ContentEntityInterface type check in listEntities()
  • PHPStan ignore patterns are reasonable for Drupal-specific idioms

Minor Suggestions (Non-blocking)

1. Entity order preservation in loadEntities()

loadMultiple() returns entities keyed by ID but not necessarily in input order. If order matters:

$result = [];
foreach ($entity_ids as $id) {
  if (isset($entities[$id]) && $entities[$id] instanceof ContentEntityInterface) {
    $result[$id] = $entities[$id];
  }
}
return $result;

Not critical since most consumers just iterate.

2. getPlugins() return structure (line 128 of interface)

The PHPDoc could document the expected array structure more explicitly, similar to how listEntities() mentions "Array of entity summaries."


Summary

Clean implementation that follows Drupal best practices. Code is well-structured, properly typed, and addresses all three issues as designed.

- Preserve input order in loadEntities() method
- Document getPlugins() return structure in interface PHPDoc
@jjroelofs jjroelofs merged commit 44fc899 into 1.x Jan 28, 2026
2 checks passed
@jjroelofs jjroelofs deleted the feat/improvements branch January 28, 2026 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants