diff options
Diffstat (limited to 'plugins/jetpack/sync/class.jetpack-sync-queue.php')
-rw-r--r-- | plugins/jetpack/sync/class.jetpack-sync-queue.php | 55 |
1 files changed, 50 insertions, 5 deletions
diff --git a/plugins/jetpack/sync/class.jetpack-sync-queue.php b/plugins/jetpack/sync/class.jetpack-sync-queue.php index 19ba6b16..e700b933 100644 --- a/plugins/jetpack/sync/class.jetpack-sync-queue.php +++ b/plugins/jetpack/sync/class.jetpack-sync-queue.php @@ -321,22 +321,67 @@ class Jetpack_Sync_Queue { } function unlock() { - $this->delete_checkout_id(); + return $this->delete_checkout_id(); } private function get_checkout_id() { - return get_transient( $this->get_checkout_transient_name() ); + global $wpdb; + $checkout_value = $wpdb->get_var( + $wpdb->prepare( + "SELECT option_value FROM $wpdb->options WHERE option_name = %s", + $this->get_lock_option_name() + ) + ); + + if ( $checkout_value ) { + list( $checkout_id, $timestamp ) = explode( ':', $checkout_value ); + if ( intval( $timestamp ) > time() ) { + return $checkout_id; + } + } + + return false; } private function set_checkout_id( $checkout_id ) { - return set_transient( $this->get_checkout_transient_name(), $checkout_id, 5 * 60 ); // 5 minute timeout + global $wpdb; + + $expires = time() + Jetpack_Sync_Defaults::$default_sync_queue_lock_timeout; + $updated_num = $wpdb->query( + $wpdb->prepare( + "UPDATE $wpdb->options SET option_value = %s WHERE option_name = %s", + "$checkout_id:$expires", + $this->get_lock_option_name() + ) + ); + + if ( ! $updated_num ) { + $updated_num = $wpdb->query( + $wpdb->prepare( + "INSERT INTO $wpdb->options ( option_name, option_value, autoload ) VALUES ( %s, %s, 'no' )", + $this->get_lock_option_name(), + "$checkout_id:$expires" + ) + ); + } + + return $updated_num; } private function delete_checkout_id() { - delete_transient( $this->get_checkout_transient_name() ); + global $wpdb; + // rather than delete, which causes fragmentation, we update in place + return $wpdb->query( + $wpdb->prepare( + "UPDATE $wpdb->options SET option_value = %s WHERE option_name = %s", + "0:0", + $this->get_lock_option_name() + ) + ); + } - private function get_checkout_transient_name() { + private function get_lock_option_name() { return "jpsq_{$this->id}_checkout"; } |