[wp-trac] [WordPress Trac] #30837: Updating "about ten percent" code or comment
WordPress Trac
noreply at wordpress.org
Wed Dec 24 16:46:41 UTC 2014
#30837: Updating "about ten percent" code or comment
----------------------------+------------------------------
Reporter: dmchale | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Administration | Version: trunk
Severity: normal | Resolution:
Keywords: | Focuses:
----------------------------+------------------------------
Description changed by SergeyBiryukov:
Old description:
> Changeset 21422 introduced a new comment to /wp-admin/admin.php ...
> https://core.trac.wordpress.org/changeset/21422
>
> {{{
> // If 50 or fewer sites, run every time. Else, run "about ten percent" of
> the time. Shh, don't check that math.
> if ( $c <= 50 || ( $c > 50 && mt_rand( 0, (int)( $c / 50 ) ) == 1 ) ) {
> }}}
>
> Sorry, I checked the math :)
>
> While I appreciate the end of the comment, it fails to let me know what
> SHOULD be happening here. The code as it's written is only going to
> perform a coin flip for all values of $c up to 99. At 100+, it becomes a
> 1-in-3. Every iteration of 50 brings us down a little more.
>
> Is the code fine as-is, or should it be rewritten to only perform the
> conditional code every 10% of the time? The docblock above this code
> simply says "If the network is 50 sites or less, it will run every time.
> Otherwise, it will throttle itself to reduce load." It's unclear what
> type of throttling is intended.
>
> I'm happy to submit a patch to fix the code OR the comment, but I'm not
> even clear on what the intent is. I'm hoping a ticket helps to clear
> things up.
New description:
Changeset [21422] introduced a new comment to /wp-admin/admin.php ...
{{{
// If 50 or fewer sites, run every time. Else, run "about ten percent" of
the time. Shh, don't check that math.
if ( $c <= 50 || ( $c > 50 && mt_rand( 0, (int)( $c / 50 ) ) == 1 ) ) {
}}}
Sorry, I checked the math :)
While I appreciate the end of the comment, it fails to let me know what
SHOULD be happening here. The code as it's written is only going to
perform a coin flip for all values of $c up to 99. At 100+, it becomes a
1-in-3. Every iteration of 50 brings us down a little more.
Is the code fine as-is, or should it be rewritten to only perform the
conditional code every 10% of the time? The docblock above this code
simply says "If the network is 50 sites or less, it will run every time.
Otherwise, it will throttle itself to reduce load." It's unclear what type
of throttling is intended.
I'm happy to submit a patch to fix the code OR the comment, but I'm not
even clear on what the intent is. I'm hoping a ticket helps to clear
things up.
--
--
Ticket URL: <https://core.trac.wordpress.org/ticket/30837#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list