Skip to content

Commit fb0ca9d

Browse files
fajardoleoswashata
authored andcommitted
[cron] Improved the scheduling of the install sync cron job.
1 parent 3cbfe00 commit fb0ca9d

File tree

1 file changed

+31
-20
lines changed

1 file changed

+31
-20
lines changed

includes/class-freemius.php

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5451,7 +5451,7 @@ function _plugin_code_type_changed() {
54515451

54525452
if ( $this->is_registered() ) {
54535453
// Schedule code type changes event.
5454-
$this->schedule_install_sync();
5454+
$this->maybe_schedule_install_sync_cron();
54555455
}
54565456

54575457
/**
@@ -6514,6 +6514,33 @@ private function maybe_schedule_sync_cron() {
65146514
$this->schedule_sync_cron();
65156515
}
65166516

6517+
/**
6518+
* Instead of running blocking install sync event, execute non blocking scheduled cron job.
6519+
*
6520+
* @param int $except_blog_id Since 2.0.0 when running in a multisite network environment, the cron execution is consolidated. This param allows excluding specified blog ID from being the cron job executor.
6521+
*
6522+
* @author Leo Fajardo (@leorw)
6523+
* @since 2.9.1
6524+
*/
6525+
private function maybe_schedule_install_sync_cron( $except_blog_id = 0 ) {
6526+
if ( ! $this->is_user_in_admin() ) {
6527+
return;
6528+
}
6529+
6530+
if ( $this->is_clone() ) {
6531+
return;
6532+
}
6533+
6534+
if (
6535+
// The event has been properly scheduled, so no need to reschedule it.
6536+
is_numeric( $this->next_install_sync() )
6537+
) {
6538+
return;
6539+
}
6540+
6541+
$this->schedule_cron( 'install_sync', 'install_sync', 'single', WP_FS__SCRIPT_START_TIME, false, $except_blog_id );
6542+
}
6543+
65176544
/**
65186545
* @author Vova Feldman (@svovaf)
65196546
* @since 1.1.7.3
@@ -6611,22 +6638,6 @@ private function get_install_sync_cron_blog_id() {
66116638
return $this->get_cron_blog_id( 'install_sync' );
66126639
}
66136640

6614-
/**
6615-
* Instead of running blocking install sync event, execute non blocking scheduled wp-cron.
6616-
*
6617-
* @author Vova Feldman (@svovaf)
6618-
* @since 1.1.7.3
6619-
*
6620-
* @param int $except_blog_id Since 2.0.0 when running in a multisite network environment, the cron execution is consolidated. This param allows excluding excluded specified blog ID from being the cron executor.
6621-
*/
6622-
private function schedule_install_sync( $except_blog_id = 0 ) {
6623-
if ( $this->is_clone() ) {
6624-
return;
6625-
}
6626-
6627-
$this->schedule_cron( 'install_sync', 'install_sync', 'single', WP_FS__SCRIPT_START_TIME, false, $except_blog_id );
6628-
}
6629-
66306641
/**
66316642
* Unix timestamp for previous install sync cron execution or false if never executed.
66326643
*
@@ -7432,7 +7443,7 @@ function _activate_plugin_event_hook() {
74327443

74337444
// Schedule re-activation event and sync.
74347445
// $this->sync_install( array(), true );
7435-
$this->schedule_install_sync();
7446+
$this->maybe_schedule_install_sync_cron();
74367447

74377448
// If activating the premium module version, add an admin notice to congratulate for an upgrade completion.
74387449
if ( $is_premium_version_activation ) {
@@ -8623,7 +8634,7 @@ private function update_plugin_version_event() {
86238634
return;
86248635
}
86258636

8626-
$this->schedule_install_sync();
8637+
$this->maybe_schedule_install_sync_cron();
86278638
// $this->sync_install( array(), true );
86288639
}
86298640

@@ -15981,7 +15992,7 @@ private function update_multisite_data_after_site_deactivation( $context_blog_id
1598115992
if ( $this->is_install_sync_scheduled() &&
1598215993
$context_blog_id == $this->get_install_sync_cron_blog_id()
1598315994
) {
15984-
$this->schedule_install_sync( $context_blog_id );
15995+
$this->maybe_schedule_install_sync_cron( $context_blog_id );
1598515996
}
1598615997
}
1598715998

0 commit comments

Comments
 (0)