Skip to content

Add CacheInvalidationTrait for hook registration - #461

Open
thinklanguages wants to merge 1 commit into
mainfrom
codex/add-cacheinvalidationtrait-and-refactor-usage
Open

Add CacheInvalidationTrait for hook registration#461
thinklanguages wants to merge 1 commit into
mainfrom
codex/add-cacheinvalidationtrait-and-refactor-usage

Conversation

@thinklanguages

@thinklanguages thinklanguages commented Jun 27, 2025

Copy link
Copy Markdown
Owner

Summary

  • implement CacheInvalidationTrait to consolidate cache invalidation hooks
  • use the trait in InventoryCache and PostsQueryService

Testing

  • composer lint (fails: command not found)
  • composer test (fails: command not found)

https://chatgpt.com/codex/tasks/task_e_685e4174b1b88327bda915bcc8f455c5

Description by Korbit AI

What change is being made?

Add a CacheInvalidationTrait to centralize and simplify the registration of hooks for cache invalidation across classes, applying it to both InventoryCache and PostsQueryService.

Why are these changes being made?

The changes aim to reduce code duplication and improve maintainability by introducing a reusable trait that handles hook registration for cache invalidation, simplifying hook management in both the InventoryCache and PostsQueryService. This approach provides a cleaner and more consistent method to handle cache invalidation triggers.

Is this description stale? Ask me to generate a new description by commenting /korbit-generate-pr-description

@korbit-ai korbit-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review by Korbit AI

Korbit automatically attempts to detect when you fix issues in new commits.
Category Issue Status
Functionality Post Status Transition Parameters Not Handled ▹ view
Files scanned
File Path Reviewed
nuclear-engagement/inc/Traits/CacheInvalidationTrait.php
nuclear-engagement/inc/Core/InventoryCache.php
nuclear-engagement/inc/Services/PostsQueryService.php

Explore our documentation to understand the languages and file types we support and the files we ignore.

Check out our docs on how you can make Korbit work best for you and your team.

Loving Korbit!? Share us on LinkedIn Reddit and X

'deleted_post',
'trashed_post',
'untrashed_post',
'transition_post_status',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Post Status Transition Parameters Not Handled category Functionality

Tell me more
What is the issue?

The 'transition_post_status' hook callback doesn't account for the specific parameters passed by WordPress (new status, old status, post object), which are needed to make informed cache invalidation decisions.

Why this matters

Without handling the specific status transition parameters, the cache might be invalidated unnecessarily, such as when transitioning to 'draft' or other non-public statuses.

Suggested change ∙ Feature Preview

Modify the trait to allow for specific parameter handling in the callback:

protected static function register_cache_invalidation_hooks( callable $callback, callable $transition_callback = null ): void {
    // ... other hooks ...
    
    add_action( 'transition_post_status', $transition_callback ?? $callback, 999, 3 );
    
    // ... remaining hooks ...
}
Provide feedback to improve future suggestions

Nice Catch Incorrect Not in Scope Not in coding standard Other

💬 Looking for more details? Reply to this comment to chat with Korbit.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant