[wp-trac] [WordPress Trac] #54825: Heartbeat minimalInterval option causing incorrect value of mainInterval

WordPress Trac noreply at wordpress.org
Fri Jan 14 21:59:12 UTC 2022


#54825: Heartbeat minimalInterval option causing incorrect value of mainInterval
--------------------------+-----------------------------
 Reporter:  tabrisrp      |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Looking at the code of `heartbeat.js`, I think there is a bug in it when
 `minimalInterval` is used.

 In the `initialize` function:

 - If `options.minimalInterval` is set, and is between 0 and 120, it's
 multiplicated by 1000 and assigned to `settings.minimalInterval`
 - After that, if `settings.minimalInterval` is superior to
 `settings.mainInterval` (which is likely always the case with the
 multiplication), the new value of `settings.mainInterval` is
 `settings.minimalInterval`
 - And then a bit further down, the value of `settings.mainInterval` is
 multiplied by 1000 to convert to microseconds. But it was already the case
 when using `options.minimalInterval`, so the value ends up being incorrect
 120 000 000 microseconds instead of the expected 120 000 ms

 As `settings.minimalInterval` is used against values in microseconds in
 other parts, a solution could be to do the following when assigning the
 value to `mainInterval`:


 {{{
 if ( settings.minimalInterval && settings.mainInterval <
 settings.minimalInterval ) {
         settings.mainInterval = settings.minimalInterval / 1000;
 }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/54825>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list