CARVIEW |
Select Language
HTTP/2 200
server: nginx
date: Fri, 10 Oct 2025 06:57:50 GMT
content-type: text/html;charset=utf-8
vary: Accept-Encoding
etag: W/"anonymous/Tue, 05 Aug 2025 16:28:15 GMT/False"
cache-control: must-revalidate
expires: Fri, 01 Jan 1999 00:00:00 GMT
alt-svc: h3=":443"; ma=86400
strict-transport-security: max-age=31536000
x-frame-options: SAMEORIGIN
content-encoding: gzip
63045-cache-count_many_users_posts.diff on Ticket #63045 – Attachment
– WordPress Trac
Ticket #63045: 63045-cache-count_many_users_posts.diff
File 63045-cache-count_many_users_posts.diff, 1.2 KB (added by sachinrajcp123, 2 months ago) |
---|
Line | |
---|---|
1 | Index: src/wp-includes/user.php |
2 | =================================================================== |
3 | --- src/wp-includes/user.php (revision 60000) |
4 | +++ src/wp-includes/user.php (working copy) |
5 | @@ |
6 | function count_many_users_posts( $users, $post_type = 'post', $public_only = false ) { |
7 | global $wpdb; |
8 | |
9 | if ( empty( $users ) || ! is_array( $users ) ) { |
10 | return array(); |
11 | } |
12 | |
13 | + $cache_key = 'count_many_users_posts:' . md5( maybe_serialize( $users ) . '|' . $post_type . '|' . ( $public_only ? '1' : '0' ) ); |
14 | + $cached = wp_cache_get( $cache_key, 'counts' ); |
15 | + if ( false !== $cached ) { |
16 | + return $cached; |
17 | + } |
18 | + |
19 | $users = array_map( 'intval', $users ); |
20 | |
21 | $where = get_posts_by_author_sql( $post_type, true, $users, $public_only ); |
22 | $where = preg_replace( '/^\s*AND\s*/', '', $where ); |
23 | |
24 | $userlist = implode( ',', $users ); |
25 | |
26 | $count = $wpdb->get_results( "SELECT post_author, COUNT(*) AS post_count FROM $wpdb->posts WHERE $where AND post_author IN ($userlist) GROUP BY post_author", ARRAY_A ); |
27 | |
28 | $counts = array_fill_keys( $users, 0 ); |
29 | foreach ( $count as $row ) { |
30 | $counts[ $row['post_author'] ] = (int) $row['post_count']; |
31 | } |
32 | + |
33 | + wp_cache_set( $cache_key, $counts, 'counts' ); |
34 | |
35 | return $counts; |
36 | } |