Make WordPress Core

Changeset 59016


Ignore:
Timestamp:
09/11/2024 11:07:26 PM (4 weeks ago)
Author:
peterwilsoncc
Message:

Administration: Increase frequency of heartbeat API requests.

Increases the frequency of heartbeat API requests from once every 15 seconds to once every 10 seconds.

The purpose of this change is to reduce the length of time before a post becomes unlocked as a user navigates around the WordPress Dashboard and ceases editing a post.

wp.heartbeat.interval() has been modified to allow theme and plugin authors to set the heartbeat interval to any value between one second and one hour rather than limiting them to a fixed set of values.

Props azaozz, annezazu, jorbin, kirasong.
Fixes #61960.

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/admin/inline-edit-post.js

    r58894 r59016  
    251251                    // Get the term label text.
    252252                    var label = $( this ).parent().text();
    253                     // Set indeterminate states for the backend. Add accessible text for indeterminate inputs. 
     253                    // Set indeterminate states for the backend. Add accessible text for indeterminate inputs.
    254254                    $( this ).after( '<input type="hidden" name="indeterminate_post_category[]" value="' + $( this ).val() + '">' ).attr( 'aria-label', label.trim() + ': ' + wp.i18n.__( 'Some selected posts have this category' ) );
    255255                }
     
    604604$( function() {
    605605
    606     // Set the heartbeat interval to 15 seconds.
     606    // Set the heartbeat interval to 10 seconds.
    607607    if ( typeof wp !== 'undefined' && wp.heartbeat ) {
    608         wp.heartbeat.interval( 15 );
     608        wp.heartbeat.interval( 10 );
    609609    }
    610610}).on( 'heartbeat-tick.wp-check-locked-posts', function( e, data ) {
  • trunk/src/js/_enqueues/admin/post.js

    r57584 r59016  
    344344    }).filter(':visible').find('.wp-tab-first').trigger( 'focus' );
    345345
    346     // Set the heartbeat interval to 15 seconds if post lock dialogs are enabled.
     346    // Set the heartbeat interval to 10 seconds if post lock dialogs are enabled.
    347347    if ( wp.heartbeat && $('#post-lock-dialog').length ) {
    348         wp.heartbeat.interval( 15 );
     348        wp.heartbeat.interval( 10 );
    349349    }
    350350
  • trunk/src/js/_enqueues/wp/heartbeat.js

    r56809 r59016  
    133133
    134134                /*
    135                  * The interval can be from 15 to 120 seconds and can be set temporarily to 5 seconds.
    136                  * It can be set in the initial options or changed later through JS and/or through PHP.
     135                 * Logic check: the interval can be from 1 to 3600 seconds and can be set temporarily
     136                 * to 5 seconds. It can be set in the initial options or changed later from JS
     137                 * or from PHP through the AJAX responses.
    137138                 */
    138139                if ( options.interval ) {
    139140                    settings.mainInterval = options.interval;
    140141
    141                     if ( settings.mainInterval < 15 ) {
    142                         settings.mainInterval = 15;
    143                     } else if ( settings.mainInterval > 120 ) {
    144                         settings.mainInterval = 120;
     142                    if ( settings.mainInterval < 1 ) {
     143                        settings.mainInterval = 1;
     144                    } else if ( settings.mainInterval > 3600 ) {
     145                        settings.mainInterval = 3600;
    145146                    }
    146147                }
     
    722723         * @memberOf wp.heartbeat.prototype
    723724         *
    724          * @param {string|number} speed Interval: 'fast' or 5, 15, 30, 60, 120.
     725         * @param {string|number} speed Interval: 'fast' or integer between 1 and 3600 (seconds).
    725726         *                              Fast equals 5.
    726          * @param {string}        ticks Tells how many ticks before the interval reverts
    727          *                              back. Used with speed = 'fast' or 5.
     727         * @param {number}        ticks Tells how many ticks before the interval reverts back.
     728         *                              Value must be between 1 and 30. Used with speed = 'fast' or 5.
    728729         *
    729730         * @return {number} Current interval in seconds.
     
    734735
    735736            if ( speed ) {
    736                 switch ( speed ) {
    737                     case 'fast':
    738                     case 5:
    739                         newInterval = 5000;
    740                         break;
    741                     case 15:
    742                         newInterval = 15000;
    743                         break;
    744                     case 30:
    745                         newInterval = 30000;
    746                         break;
    747                     case 60:
    748                         newInterval = 60000;
    749                         break;
    750                     case 120:
    751                         newInterval = 120000;
    752                         break;
    753                     case 'long-polling':
    754                         // Allow long polling (experimental).
    755                         settings.mainInterval = 0;
    756                         return 0;
    757                     default:
     737                if ( 'fast' === speed ) {
     738                    // Special case, see below.
     739                    newInterval = 5000;
     740                } else if ( 'long-polling' === speed ) {
     741                    // Allow long polling (experimental).
     742                    settings.mainInterval = 0;
     743                    return 0;
     744                } else {
     745                    speed = parseInt( speed, 10 );
     746
     747                    if ( speed >= 1 && speed <= 3600 ) {
     748                        newInterval = speed * 1000;
     749                    } else {
    758750                        newInterval = settings.originalInterval;
     751                    }
    759752                }
    760753
     
    763756                }
    764757
     758                // Special case, runs for a number of ticks then reverts to the previous interval.
    765759                if ( 5000 === newInterval ) {
    766760                    ticks = parseInt( ticks, 10 ) || 30;
  • trunk/src/wp-admin/edit-form-blocks.php

    r58904 r59016  
    122122    sprintf( 'var _wpMetaBoxUrl = %s;', wp_json_encode( $meta_box_url ) ),
    123123    'before'
     124);
     125
     126// Set Heartbeat interval to 10 seconds, used to refresh post locks.
     127wp_add_inline_script(
     128    'heartbeat',
     129    'if ( window.wp && window.wp.heartbeat ) {
     130        window.wp.heartbeat.interval( 10 );
     131    }'
    124132);
    125133
Note: See TracChangeset for help on using the changeset viewer.