Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

author-categories-cache #1935

Merged
merged 1 commit into from
Dec 12, 2024
Merged

author-categories-cache #1935

merged 1 commit into from
Dec 12, 2024

Conversation

ojopaul
Copy link
Collaborator

@ojopaul ojopaul commented Dec 2, 2024

Description

Moving Authors to new category is not reflecting after saving and reloading post #1932

Benefits

fix #1932

Possible drawbacks

Applicable issues

#1932

Checklist

  • I have created a specific branch for this pull request before committing, starting off the current HEAD of development branch.
  • I'm submitting to the development, feature/hotfix/release branch. (Do not submit to the master branch!)
  • This pull request relates to a specific problem (bug or improvement).
  • I have mentioned the issue number in the pull request description text.
  • All the issues mentioned in this pull request relate to the problem I'm trying to solve.
  • The code I'm sending follows the PSR-12 coding style.

@andergmartins andergmartins self-requested a review December 2, 2024 15:42
Copy link
Contributor

@andergmartins andergmartins left a comment

Choose a reason for hiding this comment

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

@ojopaul I detected a few things that might be fixed to improve the code cleanliness. I also think this would help to find a fix for the cache issue. I'm still checking it deeper to help address the remaining issue on Enabling/Disabling author categories.

Action publishpress_authors_flush_cache is inconsistent.

I see the action publishpress_authors_flush_cache being used with different arguments for different purposes. It is used passing one int, an array of ints, and without any argument. This can be confusing, and I think its implementation is incomplete.

Issues Identified:

  1. Inconsistent Argument Types: The action publishpress_authors_flush_cache is invoked with different types of arguments (single int, array of ints, and no argument). This inconsistency can lead to unexpected behavior.

  2. Improper Handling of Arrays: When an array of post IDs is passed, the method Post_Editor::flush_cache calls wp_cache_delete for example, which expects a string or int, not an array. This can cause errors.

  3. Missing Default Value: The method flush_cache requires a post_id but does not have a default value, which can cause an error when the action is called without a post ID.

  4. Single Responsibility Principle Violation: The current implementation of flush_cache does multiple things, which violates the single responsibility principle.

Suggestions for Improvement:

  • Separate Actions for Different Use Cases:

    • Keep the action publishpress_authors_flush_cache for cases when it does not receive any argument.
    • Create another action publishpress_authors_flush_cache_for_post that receives an array or int with post ID(s). This action should handle each post ID individually.
  • Refactor flush_cache Method:

    • Update the flush_cache method to handle arrays of post IDs by iterating over them and calling wp_cache_delete for each ID.

@ojopaul
Copy link
Collaborator Author

ojopaul commented Dec 12, 2024

Thanks for your comment @andergmartins I'm making the updates now on #1952

@ojopaul ojopaul merged commit 468af4e into development Dec 12, 2024
2 of 5 checks passed
@ojopaul ojopaul deleted the author-categories-cache branch December 12, 2024 07:13
@ojopaul ojopaul restored the author-categories-cache branch December 12, 2024 07:13
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.

Moving Authors to new category is not reflecting after saving and reloading post
2 participants