Automattic / woocommerce-services

WooCommerce Services is a feature plugin that integrates hosted services into WooCommerce (3.0+), and currently includes automated tax rates and the ability to purchase and print USPS shipping labels.
GNU General Public License v2.0
105 stars 20 forks source link

[HC] woocommerce.com requested on every admin page #2738

Open anastas10s-afk opened 1 month ago

anastas10s-afk commented 1 month ago

The https://api.woocommerce.com/payment/sift URL is being requested on every page in the admin, adding .67s (depending on the server response time) to the page generation time of admin pages.

The external request to the sift URL is found within the admin_print_footer_scripts action in the woocommerce-services\woocommerce-services.php file, on line #897: add_action( ‘admin_print_footer_scripts’, array( $this, ‘add_sift_js_tracker’ ) );

This will load the “add_sift_js_tracker” function on every admin page, which then requests https://api.woocommerce.com/payment/sift

This can be seen below in the add_sift_js_tracker function which calls “get_sift_configuration” that makes the HTTP request to the woocomerce.com/payment/sift URL

    public function add_sift_js_tracker() {
        $sift_configurations = $this->api_client->get_sift_configuration();
    }
    public function get_sift_configuration() {
        return $this->request( 'GET', '/payment/sift' );
    }

Here is a tool to see the response time of that request from around the world: https://tools.keycdn.com/performance?url=https://api.woocommerce.com/payment/sift

From Sydney it’s taking .74s to respond . This adds .74s to the backend page generation whilst WordPress waits for the request to finish.

From what I gather, related to #2689 . Reported at:

der-martin85 commented 1 week ago

I added these lines to the beginning of the add_sift_js_tracker method in "woocommerce-services.php":

                public function add_sift_js_tracker() {
                        global $pagenow;
                        if ($pagenow !== 'admin.php' || !isset($_GET['page']) || !in_array($_GET['page'], ['wc-orders'])) return;

So now the tracker is only added to pages where I think it is needed.

Maybe this can be solved by the page that requires the tracker to set some global variable that is being checked in the method instead of checking a list of pages in the method.

AntonyXSI commented 6 days ago

Is there a reason it needs to load on the orders page? Ideally there wouldn't be any external requests impacting the load time on the order listings page as it will be requested often. If it is required is there any way to cache the api.woocommerce.com/payment/sift get request for a short period or does the nonce, signature etc returned from that request need to be dynamic.

Bear in mind the wc-orders page is only for when HPOS is enabled otherwise the standard post type edit screen is requested (edit.php?post_type=shop_order)

der-martin85 commented 6 days ago

I'm not 100% sure what this thing is used for, but I guess it's for creating Shipping Labels and on the wc-orders page (or the shop_order page) you can create Shipping Labels.

But, I will leave this conversation as I uninstalled the plugin, because in my search through why we have it in the first place I found out, that we don't need it. We had another Plugin for the Labels.