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

When terms get updated, reindex affected posts asynchronously #40

Open
mboynes opened this issue Sep 24, 2016 · 1 comment
Open

When terms get updated, reindex affected posts asynchronously #40

mboynes opened this issue Sep 24, 2016 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@mboynes
Copy link
Contributor

mboynes commented Sep 24, 2016

Likely requires: #98

When a term is updated (and, that update impacts term data stored with posts, which OOTB includes the slug, name, and parent), an async task should kick off which loops through all posts in the term and reindexes them. Note that a term could have any number of posts (thousands, even millions!), so care must be taken to do this as efficiently as possible.

Implementation Notes

After #98, that async task could simply update the post meta to flag that the post needs reindexing, and a separate indexing task will handle that process. However, that ultimately requires querying for each post twice: the first time via term, and the second via post meta. It might make more sense to reindex the post in the same async process that queries for the posts in the updated term, although that would likely be less DRY.

@mboynes
Copy link
Contributor Author

mboynes commented Feb 2, 2024

This could all be done pretty efficiently in MySQL, and we'd just need to clear the relevant object cache keys. In short, query for all post ids in the term, and insert into the post meta table the key, value _sp_index,1. The query could be as simple as...

$wpdb->query(
    $wpdb->prepare(
        "INSERT INTO {$wpdb->postmeta} (`post_id`, `meta_key`, `meta_value`)
        SELECT `object_id`, '_sp_index', '1'
        FROM {$wpdb->term_relationships}
        WHERE `term_taxonomy_id` = %d",
        $term_id
    )
);

Not sure offhand what object cache keys would need to be cleared after that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant