WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 3 years ago

#12531 closed enhancement (duplicate)

Improve get_blog_count(), get_user_count() and get_sitestats()

Reported by: ocean90 Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Multisite Keywords: has-patch
Focuses: Cc:

Description

We can use *_site_transients().

More information in get_blog_count() and get_user_count()
(I use/need this information for #12460)

I also remove get_sitestats() because we have the two other functions.

Attachments (9)

12531.patch (5.5 KB) - added by ocean90 4 years ago.
12531.2.patch (6.1 KB) - added by ocean90 4 years ago.
add get_sitestats() to ms-deprecated.php
12531.3.patch (7.1 KB) - added by ocean90 4 years ago.
ms-sites.php.3a.diff (6.7 KB) - added by ocean90 4 years ago.
alternative: leave get_sitestats() undeprecated
12531.4.patch (7.7 KB) - added by ocean90 4 years ago.
remove unneeded prepare()
12531.5.patch (7.9 KB) - added by ocean90 4 years ago.
onlyimprove.patch (3.1 KB) - added by ocean90 4 years ago.
12531.6.2.patch (4.1 KB) - added by ocean90 4 years ago.
12531.6.patch (4.1 KB) - added by ocean90 4 years ago.

Download all attachments as: .zip

Change History (25)

ocean904 years ago

comment:1 ocean904 years ago

  • Summary changed from Improve get_sitestats() and get_user_count() to Improve get_blog_count() and get_user_count(), remove get_sitestats()

comment:2 scribu4 years ago

  • Component changed from General to Multisite
  • Keywords multisite removed

Unless get_sitestats() was introduced in WP 3.0, you should move it to deprecated.php instead of removing it completely.

ocean904 years ago

add get_sitestats() to ms-deprecated.php

comment:3 follow-up: ryan4 years ago

We can't change the return type of get_user_count() or get_blog_count(), and get_sitestats() must still be functional. Those are all used in MU and back compat must be maintained. All of those would have to be deprecated and replaced with new functions. Also, see count_users().

comment:4 in reply to: ↑ 3 ocean904 years ago

Ok, I declare get_blog_count(), get_user_count(), get_sitestats() as deprecated functions and create ms_count_blogs() and ms_count_users() (like wp_count_comments).

ocean904 years ago

ocean904 years ago

alternative: leave get_sitestats() undeprecated

comment:5 dd324 years ago

Also: No need to pass hard-coded queries through prepare() before querying them, That should only be done if placeholders are used within the query (ie. %d and %s); - Not sure why the original function is doing that.

ocean904 years ago

remove unneeded prepare()

comment:6 ryan4 years ago

Doing that may counts will kill performance on sites with lots of blogs and users. Is this for showing counts for the status filters on the ms-sites and users pages? I suggest leaving the counts off. Counting will make those pages unusably slow.

comment:7 nacin4 years ago

(In [13664]) get_blog_count() returns a number, not an object. Also, i18n fixes -- add plural string, and translator context. see #12531 for get_blog_count() discussion. see #12409 for ms-sites cleanup.

comment:8 ocean904 years ago

ryan: Yep, it should be for that.

I reduce the queries to one and create 1,100 sites and make some tests and the counting doesn't make the site really 'unusably slow'. The results are also saved in the site transient.
So, I upload the new patch.

ocean904 years ago

comment:9 wpmuguru4 years ago

If it were me, I would put the counting of site/user statuses in a plugin and use hooks to update the counts.

comment:10 ryan4 years ago

Try it with 10 million users and 10 million blogs.

I'd rather push this to 3.1.

comment:11 nacin4 years ago

  • Milestone changed from 3.0 to 3.1
  • Type changed from defect (bug) to enhancement

comment:12 ocean904 years ago

  • Summary changed from Improve get_blog_count() and get_user_count(), remove get_sitestats() to Improve get_blog_count(), get_user_count() and get_sitestats()

Ok, but we should improve the existing function for 3.0. See patch.

ocean904 years ago

comment:13 nacin4 years ago

  • Milestone changed from 3.1 to 3.0

Moving back to 3.0 so we can update this to use the transients API.

We'll want to keep the timeout though.

ocean904 years ago

ocean904 years ago

comment:14 ocean904 years ago

12531.6.patch is a new version with *_site_transients().

Replying to nacin:

We'll want to keep the timeout though.

I don't think that we need the timeout anymore, because we shouldn't need a new count, if nothing is changed.

comment:15 ryan4 years ago

  • Milestone changed from 3.0 to 3.1

These should be computed via cron jobs and stored in an option. The recalculation cost is too high to store it in a transient that might get pushed out of cache.

comment:16 nacin3 years ago

  • Milestone Awaiting Triage deleted
  • Resolution set to duplicate
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.