Skip to content

Conversation

@dspachos
Copy link
Contributor

No description provided.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @dspachos, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request adds functionality to automatically update the Search API index for entities that reference other entities when those referenced entities are changed or deleted. This is particularly useful for ensuring that content like nodes, which might embed or reference media or other entities, stays up-to-date in the search index when the referenced content is modified. The implementation uses the entity_usage module to find referencing entities and a new service to trigger the Search API updates.

Highlights

  • Search API Index Updates: Introduced a new service (search.api.index.update) that leverages the entity_usage module to find all entities that reference a given entity. When a referenced entity is saved or deleted, this service triggers a Search API index update for all its source entities.
  • Media Entity Integration: Implemented hook_media_presave and hook_media_delete to automatically call the new search.api.index.update service whenever a Media entity is saved or deleted. This ensures that content referencing media (like nodes with media in their body fields) is re-indexed when the media changes.
  • Kernel Test Coverage: Added a new kernel test (SearchApiIndexUpdateTest) to verify that updating a media entity correctly queues both the media entity itself and any referencing nodes (specifically tested with media embedded in a Gutenberg block) for Search API indexing.
  • Minor Code Style Fixes: Included minor code style adjustments (spacing around if/elseif) and removed an unused use statement in the custom module.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configureGemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot 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

This pull request introduces functionality to update the Search API index for entities when entities they reference are changed or deleted. It adds a new service SearchApiIndexUpdate that uses the entity_usage module to find dependent entities and queues them for re-indexing. The changes include implementing hooks for media entities, defining the new service, adding the service class, and providing a kernel test. The core logic appears sound, but there is temporary debugging code that needs removal, and some improvements can be made to documentation, test namespace, and potentially making the hooks more generic.

Comment on lines 26 to 58
dpm(__METHOD__);
$node = \Drupal\node\Entity\Node::load(25);
$serializer = new \Drupal\silverback_gutenberg\BlockSerializer();

$parser = new \Drupal\gutenberg\Parser\BlockParser();

$content = $node->body->getValue()[0]['value'];
//dpm($content);
$blocks = $parser->parse($content);
// dpm($blocks);

$blocks = [
[
'blockName' => 'core/paragraph',
'innerContent' => ['<p>A test paragraph</p>'],
'attrs' => [],
'innerBlocks' => [],
'innerHTML' => [],
],
[
'blockName' => 'drupalmedia/drupal-media-entity',
'attrs' => [
'caption' => 'This is the caption',
'mediaEntityIds' => [1],
],
'innerContent' => [],
'innerBlocks' => [],
'innerHTML' => [],
]
];

$html = $serializer->serialize_blocks($blocks);
dpm($html);

Choose a reason for hiding this comment

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

high

This silverback_search_form_alter function appears to contain temporary debugging code. It includes dpm calls, hardcoded entity loading (Node::load(25)), and hardcoded block structures for testing serialization. This code should be removed before merging.

Comment on lines +12 to +14
function silverback_search_media_presave(EntityInterface $entity) {
\Drupal::service('search.api.index.update')->searchApiIndexUpdate($entity);
}

Choose a reason for hiding this comment

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

medium

The hooks silverback_search_media_presave and silverback_search_media_delete are specifically implemented for the media entity type. If the intention is to trigger Search API index updates for usages of other entity types as well (e.g., nodes, taxonomy terms), consider implementing generic hook_entity_presave and hook_entity_delete and adding logic inside to check the entity type, or using event subscribers for a more modern approach.

Comment on lines +20 to +22
function silverback_search_media_delete(EntityInterface $entity) {
\Drupal::service('search.api.index.update')->searchApiIndexUpdate($entity);
}

Choose a reason for hiding this comment

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

medium

The hooks silverback_search_media_presave and silverback_search_media_delete are specifically implemented for the media entity type. If the intention is to trigger Search API index updates for usages of other entity types as well (e.g., nodes, taxonomy terms), consider implementing generic hook_entity_presave and hook_entity_delete and adding logic inside to check the entity type, or using event subscribers for a more modern approach.

Comment on lines +12 to +13
* @todo Add class description.
*/

Choose a reason for hiding this comment

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

medium

The class description is marked as @todo. Please add a proper description explaining the purpose of the SearchApiIndexUpdate class.

/**
 * Service to update Search API index for entities based on their usages.
 */

Comment on lines 247 to 248
// $this->index->indexItems();
// $tracker->trackAllItemsUpdated(['1']);

Choose a reason for hiding this comment

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

medium

These lines are commented out. Please remove commented-out code that is no longer needed.

$this->assertEquals(
[],
$tracker->getRemainingItems(),
'⚠️ Initial index matching error (1)',

Choose a reason for hiding this comment

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

medium

In test assertions, it's common practice to use "got" and "want" instead of "Initial index matching error (1)" to describe the actual and expected values for clarity.

'Got unexpected items in tracker after initial index.',

$this->assertEquals(
$expected,
$tracker->getRemainingItems(),
'⚠️ Media update index matching error (2)',

Choose a reason for hiding this comment

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

medium

In test assertions, it's common practice to use "got" and "want" instead of "Media update index matching error (2)" to describe the actual and expected values for clarity.

'Got unexpected items in tracker after media update.',

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants