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

Category sometimes doesn't get set #302

Open
snarfed opened this issue Oct 21, 2024 · 7 comments
Open

Category sometimes doesn't get set #302

snarfed opened this issue Oct 21, 2024 · 7 comments

Comments

@snarfed
Copy link
Member

snarfed commented Oct 21, 2024

Hi guys! I've noticed a bug (I think) that's bit me a few times over the last few months: occasionally posts will get created, and published, but the category in the micropub request doesn't get set.

I use category to hide replies, likes, reposts, etc from my home page, so the result is that those occasionally show up on the home page, which is a bit confusing and embarrassing 😁

I think this tends to happen when either my site or the db or both are unusually slow. I'm guessing the post is getting created, and then something hits a request or db timeout somewhere, and the rest of the processing gets cut off and the category doesn't get applied. Sounds like ideally the category should get written in the same database transaction as the post?

@janboddez
Copy link
Contributor

janboddez commented Oct 22, 2024

Categories seem to be added/mapped here:

$args['post_category'][] = $wp_cat->term_id;

This function is itself called here:

$args = static::mp_to_wp( static::$input );

And then this here line is where the resulting $args array is passed on to WordPress' wp_insert_post().

In other words, after all the inputs (including categories) are converted to a single, fairly standard WordPress post argument array, it's just core WP doing its thing.

If I'm not mistaking, core will execute multiple SQL calls; not sure this plugin can do much to work around that.

@snarfed
Copy link
Member Author

snarfed commented Oct 22, 2024

Thanks for looking at this @janboddez! That makes sense...and it's also disappointing and worrying, since it would seem to mean this will be harder to fix or do anything about, if even possible at all. 😕

@dshanske
Copy link
Member

@janboddez That's what I saw also, but wanted to do some research to see if anything popped out

@snarfed
Copy link
Member Author

snarfed commented Oct 27, 2024

This keeps happening to me. I dug in a bit just now and figured out more of what's going on. It looks like the micropub and mf2 wp_postmeta rows aren't getting written. For a successful reply, wp_postmeta has rows for the post with meta_keys micropub_auth_response, micropub_version, mf2_type, mf2_category, mf2_in-reply-to, and mf2_syndication. When this happens, none of those wp_postmeta rows are there.

Could you put the wp_postmeta writes inside the same transaction as the post write? Or something similar to have the same effect?

@dshanske
Copy link
Member

I don't see any reason it shouldn't work. From the looks of it, it is as expected. But I can try cleaning up some of the code to see if it becomes more evident. I know I've seen a category issue reported in WordPress when you try to do it in the initial post creation...but that shouldn't affect meta

@snarfed
Copy link
Member Author

snarfed commented Oct 27, 2024

This generally happens when my hosting provider is extremely slow, which happens occasionally, eg rendering a wp-admin page takes 30-60s. When I've tried to dig in, the conclusion has been that MySQL itself is unhappy, queries and writes take an unusually long time, and sometimes fail or time out altogether.

@dshanske
Copy link
Member

May seek some guidance from the community

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

No branches or pull requests

3 participants