humanmade / authorship

A modern approach to author attribution in WordPress.
GNU General Public License v3.0
66 stars 7 forks source link

Slow behaviour on admin-ajax requests #143

Open rmccue opened 6 months ago

rmccue commented 6 months ago

I'm working with a customer who is experiencing slowness on admin-ajax requests, which appears to be at least partially attributable to Authorship.

For example, on a query-attachments action (sorted by highest impact):

Screenshot 2024-02-20 at 11 30 51

The specific query here doesn't seem too strange:

{
    "post_id": "1234",
    "query": {
        "post_mime_type": "image",
        "paged": "1",
        "posts_per_page": "80",
        "orderby": "date",
        "order": "DESC"
    },
    "action": "query-attachments"
}

However, this appears to be inefficiently querying the authors for these posts; there are 99 queries total, so approx 1 query per post (plus static overhead), where each query is:

SELECT DISTINCT t.term_id
FROM wp_4_terms AS t  INNER JOIN wp_4_term_taxonomy AS tt ON t.term_id = tt.term_id INNER JOIN wp_4_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id
WHERE tt.taxonomy IN ('authorship') AND tr.object_id IN (4321)
ORDER BY tr.term_order ASC
johnbillion commented 6 months ago

Are you seeing the same issue on the main Posts listing screen in the admin area (at wp-admin/edit.php)? I just checked another site and it is indeed performing a query to fetch the terms in the authorship taxonomy once for each post ID.

My understanding is that when fetching a list of posts, the list of terms for its taxonomies should be fetched at once and cached, but that is not happening.

rmccue commented 6 months ago

Looks like it, but harder to tell there. We're also hitting another bug with that which means the performance of the page is terrible (hierarchical post list tables are ungood)

rmccue commented 6 months ago

e.g. 10% of page load (but this isn't a particularly slow one):

Screenshot 2024-02-20 at 17 25 06

This does have one query per author as well (50 queries to list 10 posts)