Opened 20 years ago
Closed 18 years ago
#1659 closed defect (bug) (fixed)
(wp_)list_authors queries
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 2.2 | Priority: | normal |
Severity: | normal | Version: | 1.5.2 |
Component: | Optimization | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
These two template tags:
wp_list_authors(<?php wp_list_authors(); ?>) and
list_authors (<?php list_authors(); ?>) (no matter what functions within them are called)
add an extra query to the database for each member registered on the blog - weather they are authors or not. On mine it adds 24 extra queries as shown below. This action should only be taken out in one database query to reduce the time for the page to load.
[24] => Array ( [0] => SELECT COUNT(*) FROM wp_posts WHERE post_author = '17' AND post_status = 'publish' [1] => 0.0088999271392822 ) [25] => Array ( [0] => SELECT COUNT(*) FROM wp_posts WHERE post_author = '15' AND post_status = 'publish' [1] => 0.008976936340332 ) [26] => Array ( [0] => SELECT COUNT(*) FROM wp_posts WHERE post_author = '4' AND post_status = 'publish' [1] => 0.009009838104248 ) [27] => Array ( [0] => SELECT COUNT(*) FROM wp_posts WHERE post_author = '19' AND post_status = 'publish' [1] => 0.0088570117950439 ) [28] => Array ( [0] => SELECT COUNT(*) FROM wp_posts WHERE post_author = '2' AND post_status = 'publish' [1] => 0.0090000629425049 ) [29] => Array ( [0] => SELECT COUNT(*) FROM wp_posts WHERE post_author = '9' AND post_status = 'publish' [1] => 0.0089190006256104 ) [30] => Array ( [0] => SELECT COUNT(*) FROM wp_posts WHERE post_author = '8' AND post_status = 'publish' [1] => 0.0088551044464111 ) [31] => Array ( [0] => SELECT COUNT(*) FROM wp_posts WHERE post_author = '13' AND post_status = 'publish' [1] => 0.011569976806641 ) [32] => Array ( [0] => SELECT COUNT(*) FROM wp_posts WHERE post_author = '12' AND post_status = 'publish' [1] => 0.010303974151611 ) [33] => Array ( [0] => SELECT COUNT(*) FROM wp_posts WHERE post_author = '14' AND post_status = 'publish' [1] => 0.0098090171813965 ) [34] => Array ( [0] => SELECT COUNT(*) FROM wp_posts WHERE post_author = '11' AND post_status = 'publish' [1] => 0.02720308303833 ) [35] => Array ( [0] => SELECT COUNT(*) FROM wp_posts WHERE post_author = '7' AND post_status = 'publish' [1] => 0.0099828243255615 ) [36] => Array ( [0] => SELECT COUNT(*) FROM wp_posts WHERE post_author = '18' AND post_status = 'publish' [1] => 0.011690855026245 ) [37] => Array ( [0] => SELECT COUNT(*) FROM wp_posts WHERE post_author = '20' AND post_status = 'publish' [1] => 0.0088968276977539 ) [38] => Array ( [0] => SELECT COUNT(*) FROM wp_posts WHERE post_author = '6' AND post_status = 'publish' [1] => 0.0089771747589111 ) [39] => Array ( [0] => SELECT COUNT(*) FROM wp_posts WHERE post_author = '10' AND post_status = 'publish' [1] => 0.0090258121490479 ) [40] => Array ( [0] => SELECT COUNT(*) FROM wp_posts WHERE post_author = '5' AND post_status = 'publish' [1] => 0.0089180469512939 ) [41] => Array ( [0] => SELECT COUNT(*) FROM wp_posts WHERE post_author = '16' AND post_status = 'publish' [1] => 0.008929967880249 )
Attachments (3)
Change History (17)
#2
@
19 years ago
- Keywords bg|2nd-opinion added; template tags removed
- Owner changed from markjaquith to graeme
- Status changed from assigned to new
Believe I've licked this. As always, there's likely a better way...
get_userdata() is still being called once per user, but (if the bug report is right) all that is being taken from the cache. Ideally the number of posts an author has (ah) authored should be part of their userdata, maybe? Anyway...
Basically, what it does is this:
It should be possible to split the logic early on, and do a different query based on your $hide_empty setting. When $hide_empty is off, no prob, do the existing query and don't bother to filter later on. If $hide_empty is on, you need to do one big fancy query that joins the authors and the post tables, and grabs the count of the $wpdb->posts.ID column... might be a tad complicated, but I don't know of a better way.