[wp-trac] [WordPress Trac] #58368: WordPress dashboard is very slow when there are many comments (and the database isn't great)
WordPress Trac
noreply at wordpress.org
Wed May 24 16:59:38 UTC 2023
#58368: WordPress dashboard is very slow when there are many comments (and the
database isn't great)
--------------------------+--------------------------
Reporter: Guss77 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: 6.3
Component: Comments | Version: 6.2.2
Severity: minor | Resolution:
Keywords: has-patch | Focuses: performance
--------------------------+--------------------------
Comment (by westonruter):
Skipping sorting when only querying for a count makes sense to me.
Per @joemcgill, the problematic code is the call to `wp_count_comments()`
in [https://github.com/WordPress/wordpress-
develop/blob/d51ee6ce097fb288aca9da1f95899fc3d77c0fa4/src/wp-
admin/menu.php#L89-L107 wp-admin/menu.php].
This function uses the object cache to [https://github.com/WordPress
/wordpress-develop/blob/d51ee6ce097fb288aca9da1f95899fc3d77c0fa4/src/wp-
includes/comment.php#L1438-L1448C2 store the comment count for a post]. If
this were made into a transient instead, this would address the lack of
persistent object cache.
Aside: @Guss77 another option for you would be to add a
`wp_count_comments` filter in [https://github.com/WordPress/wordpress-
develop/blob/d51ee6ce097fb288aca9da1f95899fc3d77c0fa4/src/wp-
includes/comment.php#L1433-L1436 that same function]. This would allow you
to short-circuit the expensive query, and you could use the query that
lacks the `ORDER BY`.
Lastly, I just wanted to note that in the AMP plugin we had this same
problem of a count in the menu slowing down admin page loads, here
specifically the count for AMP validation errors. We solved the problem by
fetching the count over the REST API and then storing it in
`sessionStorage`, and we only do the fetch once the menu item is actually
shown (via `IntersectionObserver`): this would help in the case where the
admin menu is collapsed. See the code here: https://github.com/ampproject
/amp-wp/blob/develop/assets/src/amp-validation/counts/index.js
--
Ticket URL: <https://core.trac.wordpress.org/ticket/58368#comment:14>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list