๐Ÿ’ฅ TRENDING: Ticket/ - High Quality

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#56293 closed defect (bug) (fixed)

Use 'MINUTE_IN_SECONDS' for consistency in 'update.php' file

Reported by: hztyfoon's profile hztyfoon Owned by: audrasjb's profile audrasjb
Milestone: 6.1 Priority: low
Severity: normal Version:
Component: Administration Keywords: has-patch dev-feedback
Focuses: coding-standards Cc:

Description (last modified by SergeyBiryukov)

In the 'wp-includes/update.php' file there are multiple instances where variable $timeout set to plain integer 30 like:

$timeout = 30;

I think It should be like this (MINUTE_IN_SECONDS also used multiple time in this file) as done here in this commit [53714]:

$timeout = MINUTE_IN_SECONDS / 2;

Attachments (2)

56293.patchโ€‹ (812 bytes) - added by arrasel403 3 years ago.
Patch file added for this ticket
56293.diffโ€‹ (516 bytes) - added by krupalpanchal 3 years ago.

Download all attachments as: .zip

Change History (45)

#1 in reply to: โ†‘ย description @hztyfoon
3 years ago

I think It should be like this (MINUTE_IN_SECONDS also used multiple time in this file) as done here in this commit #53714:

โฌ†๏ธ Sorry, I linked wrong ticket there. I meant this commit: [53714]

Last edited 3 years ago by SergeyBiryukov (previous) (diff)

#2 @rudlinkon
3 years ago

  • Keywords needs-patch added

#3 @audrasjb
3 years ago

  • Milestone changed from Awaiting Review to 6.1
  • Owner set to audrasjb
  • Status changed from new to reviewing

Good point!
Moving for 6.1 consideration.

This ticket was mentioned in โ€‹PR #3029 on โ€‹WordPress/wordpress-develop by โ€‹audrasjb.


3 years ago
#4

  • Keywords has-patch added; needs-patch removed

@arrasel403
3 years ago

Patch file added for this ticket

#5 @krupalpanchal
3 years ago

Added Patch

#6 @GaryJ
3 years ago

The 56293.diff patch seems unnecessarily complex. Just because we want to say 2 hours or 5 hours, doesn't mean we need to derive the 2 or the 5 from some division of the MINUTE_IN_SECONDS constant.

#7 follow-up: @hztyfoon
3 years ago

hey @krupalpanchal ,
I checked your 56293.diffโ€‹ and looks to me your changes aren't what I suggested.

To me,
2 * HOUR_IN_SECONDS makes more sense than ( MINUTE_IN_SECONDS / 30 ) * HOUR_IN_SECONDS
same goes for the other line's change.

Because, When I see 2 * HOUR_IN_SECONDS it clearly makes me understand that it's twice an hour in seconds but when there's something like ( MINUTE_IN_SECONDS / 30 ) * HOUR_IN_SECONDS it makes it more hard to read.

My point was these constants like (MINUTE_IN_SECONDS, HOUR_IN_SECONDS) can make the timing numbers more readable for a non programmer. But, I don't see how your changes make it more readable.

#8 @hztyfoon
3 years ago

oh @GaryJ,
Thanks.

U've beat me by almost MINUTE_IN_SECONDS * 2 seconds. ๐Ÿ˜Š

Last edited 3 years ago by hztyfoon (previous) (diff)

#9 in reply to: โ†‘ย 7 @audrasjb
3 years ago

The 56293.diff patch seems unnecessarily complex. Just because we want to say 2 hours or 5 hours, doesn't mean we need to derive the 2 or the 5 from some division of the MINUTE_IN_SECONDS constant.

2 * HOUR_IN_SECONDS makes more sense than ( MINUTE_IN_SECONDS / 30 ) * HOUR_IN_SECONDS
same goes for the other line's change.

Agreed.

Last edited 3 years ago by audrasjb (previous) (diff)

#10 @rudlinkon
3 years ago

@arrasel403 thanks for your patch but @audrasjb doing some extra care about this issue so I think the PR has a better solution than the patch. But you ( @arrasel403 ) are most welcome as a new contributor.

Last edited 3 years ago by rudlinkon (previous) (diff)

#11 @SergeyBiryukov
3 years ago

  • Description modified (diff)
  • Keywords changes-requested added

Thanks everyone!

// Three seconds, plus one extra second for every 10 themes.
$timeout = MINUTE_IN_SECONDS / 20 + (int) ( count( $themes ) / 10 )

I think MINUTE_IN_SECONDS / 20 is also too complicated :) Keeping that as is, especially with the "Three seconds" comment above, seems more readable to me:

// Three seconds, plus one extra second for every 10 themes.
$timeout = 3 + (int) ( count( $themes ) / 10 );

Same goes for this:

'timeout'    => $doing_cron ? MINUTE_IN_SECONDS / 2 : MINUTE_IN_SECONDS / 20,

This might be more readable:

// Half a minute when doing cron tasks, 3 seconds otherwise.
'timeout'    => $doing_cron ? MINUTE_IN_SECONDS / 2 : 3,

#12 @hztyfoon
3 years ago

Thanks @SergeyBiryukov ,

I'm not sure if it's a coincident but I was just about to make the same comment in the PR. Agreed about MINUTE_IN_SECONDS / 20 being complicated.

#13 @rudlinkon
3 years ago

Thank you @SergeyBiryukov, it would be better if you suggest this change request in the PR.

โ€‹hz-tyfoon commented on โ€‹PR #3029:


3 years ago
#14

Hey @audrasjb,
I can see U've used MINUTE_IN_SECONDS / 20 in line number 190, 411 & 692.
In my humble opinion, looks to me using MINUTE_IN_SECONDS / 20 also makes it more complicated & less readable.

@SergeyBiryukov also suggesting the same.
So, I think may be those 3 changes may not be necessary.

#15 @hztyfoon
3 years ago

Thanks @rudlinkon for your suggestion.
I made the comment in the PR.

โ€‹hz-tyfoon commented on โ€‹PR #3029:


3 years ago
#16

thanks @peterwilsoncc for reviewing.

  • 0.5 * MINUTE_IN_SECONDS is possibly ok

This one also sounds solid, readable & performance firendly to me.

The reviews of this PR didn't show up in the trac.
Hopefully, this comment is going to show up in the trac ticket.
๐Ÿ˜Š

#17 follow-up: @audrasjb
3 years ago

  • Keywords dev-feedback added; changes-requested removed
  • Priority changed from normal to low

PR updated as per @SergeyBiryukov 's proposal.
@peterwilsoncc suggested to replace MINUTE_IN_SECONDS / 2 with 0.5 * MINUTE_IN_SECONDS.

I personally find the former more readable than the latter.
That's not super important, but let's collect some feedback from other committers before shipping this tiny enhancement ;)

#18 in reply to: โ†‘ย 17 @