Skip to content
This repository has been archived by the owner on Oct 4, 2019. It is now read-only.

Commit

Permalink
Merge pull request #28 from woocommerce/fix/27-suspend-jp-sync-during…
Browse files Browse the repository at this point in the history
…-rest-response

Disable jetpack sync during REST requests
  • Loading branch information
allendav authored Jul 18, 2017
2 parents 1dc3571 + 9c11c40 commit 97f3d11
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
33 changes: 33 additions & 0 deletions hotfixes/wc-api-dev-jetpack-hotfixes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Jetpack compatibility hotfixes
*
* @since 0.7.0
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

/**
* Disables jetpack sync during rest requests to avoid lengthly (> 5 second) response
* times during the shutdown action for things like product creation
*
* See also https://core.trac.wordpress.org/ticket/41358#ticket
* See also https://github.com/Automattic/jetpack/pull/7482
*
* This can be removed once we have either of the two fixes above released
*
* See also https://github.com/woocommerce/woocommerce/pull/16158
*/

function wc_api_dev_jetpack_sync_sender_should_load( $sender_should_load ) {
$starts_with = '/wp-json/wc/v';
if ( $starts_with === substr( $_SERVER[ 'REQUEST_URI' ], 0, strlen( $starts_with ) ) ) {
$sender_should_load = false;
}

return $sender_should_load;
}

add_filter( 'jetpack_sync_sender_should_load', 'wc_api_dev_jetpack_sync_sender_should_load', 999 );
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: automattic, woothemes
Tags: woocommerce, rest-api, api
Requires at least: 4.6
Tested up to: 4.8
Stable tag: 0.6.0
Stable tag: 0.7.0
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand All @@ -25,6 +25,9 @@ This section describes how to install the plugin and get it working.

== Changelog ==

= 0.7.0 =
* Fix - disable jetpack sync during rest api requests to avoid slow responses

= 0.6.0 =
* Fix value default return on settings endpoints
* Fix broken variation image set
Expand Down
5 changes: 4 additions & 1 deletion wc-api-dev.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: WooCommerce API Dev
* Plugin URI: https://woocommerce.com/
* Description: A feature plugin providing a bleeding edge version of the WooCommerce REST API.
* Version: 0.6.0
* Version: 0.7.0
* Author: Automattic
* Author URI: https://woocommerce.com
* Requires at least: 4.4
Expand Down Expand Up @@ -117,6 +117,9 @@ public function includes() {
include_once( dirname( __FILE__ ) . '/api/class-wc-rest-dev-system-status-tools-controller.php' );
include_once( dirname( __FILE__ ) . '/api/class-wc-rest-dev-shipping-methods-controller.php' );
include_once( dirname( __FILE__ ) . '/api/class-wc-rest-dev-payment-gateways-controller.php' );

// Things that aren't related to a specific endpoint but to things like cross-plugin compatibility
include_once( dirname( __FILE__ ) . '/hotfixes/wc-api-dev-jetpack-hotfixes.php' );
}

/**
Expand Down

0 comments on commit 97f3d11

Please sign in to comment.