#27985 closed defect (bug) (fixed)
wp_enqueue_media() may be slow on very large sites
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 3.9.1 | Priority: | normal |
Severity: | normal | Version: | 3.9 |
Component: | Media | Keywords: | fixed-major commit |
Focuses: | performance | Cc: |
Description
I have sites with very large databases and I've noticed some slow queries since 3.9 on new/edit post screens:
SELECT post_mime_type, COUNT( * ) AS num_posts FROM wp_posts WHERE post_type = 'attachment' AND post_status != 'trash' GROUP BY post_mime_type
From my experience, this query can take upwards of a second to run on a large dataset. Given that it's not on every screen, and it's only really a problem on large databases, perhaps the benefits outweigh the costs. I figured it was best to open a ticket to ensure those costs are properly considered, as well as alternative solutions to get the same end result.
This query is coming from wp_count_attachments()
which is being called by wp_enqueue_media()
. It looks like this was added in #27554.
Attachments (2)
Change History (16)
#2
@
11 years ago
We could/should also cache those values. This isn't unlike is_multi_author(), though persistent cache is probably fine (versus a transient) as it isn't being used on the frontend.
#4
@
11 years ago
- Keywords has-patch needs-testing added
attachment:27985.diff is a first pass at caching the query in wp_count_attachments()
.
This ticket was mentioned in IRC in #wordpress-dev by nacin1. View the logs.
11 years ago
#7
@
11 years ago
27985.2.diff - I missed the chatter about @johnbillion doing it
#8
@
11 years ago
That's fine, my approach was going to be similar. I don't think there's any point in changing the counts
code in the media view for a point release.
I kind of feared this one, but since it was run on the media list table I didn't think too much of it.
We can change this to two queries, which would be faster:
There is no index on post_mime_type though, so this is till a where on however many attachment records there are.