如何从WC API端点请求中删除数据?

问题描述 投票:0回答:1

我正在将订单数据运送到第三方履行软件。它们默认情况下与WooCommerce REST API集成。但是,最近对我的网站和订单数据进行的一些更改增加了其他订单元。现在,当获取数量总是与504相同的订单时,其请求超时。该请求现在变得不合理,为解决此问题,我决定通过减少该请求产生的无关数据和不必要数据来进行优化。另外,我必须能够一次处理100,但我无法降低过滤器限制,该限制由第三方应用程序自动设置。

有问题的端点

wc-api/v2/orders?status=processing&page=1&filter%5Blimit%5D=100

此端点获取处理中的前100个订单,并将它们显示为JSON。

要删除的内容

  1. customer_user_agent
  2. avatar_url
  3. cogs_cost
  4. cogs_total_cost

示例响应

{
   "orders":[
      {
         "id":137314,
         "order_number":"137314",
         "created_at":"2019-09-18T18:37:06Z",
         "updated_at":"2019-09-18T18:37:07Z",
         "completed_at":"1970-01-01T00:00:00Z",
         "status":"processing",
         "currency":"USD",
         "total":"49.50",
         "subtotal":"55.00",
         "total_line_items_quantity":1,
         "total_tax":"0.00",
         "total_shipping":"0.00",
         "cart_tax":"0.00",
         "shipping_tax":"0.00",
         "total_discount":"0.00",
         "shipping_methods":"Free shipping",
         "payment_details":{
            "method_id":"nmipay",
            "method_title":"Pay with Credit Card",
            "paid":true
         },
         "billing_address":{
            "first_name":"XXX",
            "last_name":"XXXX",
            "company":"",
            "address_1":"XXXX",
            "address_2":"",
            "city":"XXXX",
            "state":"XX",
            "postcode":"XXXXX",
            "country":"US",
            "email":"XXXXXX",
            "phone":"XXXX"
         },
         "shipping_address":{
            "first_name":"XXX",
            "last_name":"XX",
            "company":"",
            "address_1":"XXXXX",
            "address_2":"",
            "city":"XXX",
            "state":"XXX",
            "postcode":"XXX",
            "country":"XXXX"
         },
         "note":"",
         "customer_ip":"98.216.25.236",
         "customer_user_agent":"mozilla\/5.0 (iphone; cpu iphone os 12_4_1 like mac os x) applewebkit\/605.1.15 (khtml, like gecko) version\/12.1.2 mobile\/15e148 safari\/604.1",
         "customer_id":127116,
         "view_order_url":"XXXXX",
         "line_items":[
            {
               "id":198261,
               "subtotal":"55.00",
               "subtotal_tax":"0.00",
               "total":"55.00",
               "total_tax":"0.00",
               "price":"55.00",
               "quantity":1,
               "tax_class":"",
               "name":"Core Hoodie - Black, Large",
               "product_id":351,
               "sku":"ss-hoodie-core-zip-blk-lg",
               "meta":[

               ],
               "bundled_by":"",
               "bundled_item_title":"",
               "bundled_items":[

               ],
               "cogs_cost":"23.15",
               "cogs_total_cost":"23.15"
            }
         ],
         "shipping_lines":[
            {
               "id":198263,
               "method_id":"free_shipping",
               "method_title":"Free shipping",
               "total":"0.00"
            }
         ],
         "tax_lines":[

         ],
         "fee_lines":[
            {
               "id":198262,
               "title":"VIP Discount",
               "tax_class":"0",
               "total":"-5.50",
               "total_tax":"0.00"
            }
         ],
         "coupon_lines":[

         ],
         "cogs_total_cost":"23.15"
      }
   ]
}

这是我得到的最远的

我发现了以下钩子,但无法触发。

woocommerce_rest_prepare_shop_order_object
woocommerce_rest_prepare_shop_order
function remove_user_agent_from_rest_api( $response, $object, $request ) {
    unset($response->data['customer_user_agent']);
    return $response;
}

function test_rest_api() {
add_filter( "woocommerce_rest_pre_insert_shop_order", "remove_user_agent_from_rest_api", 10, 2 );
add_filter( "woocommerce_rest_pre_insert_shop_order_object", "remove_user_agent_from_rest_api", 10, 2 );
}

add_action( 'rest_api_init', 'test_rest_api', 0 );

这是性能调整问题吗?

这里是来自新文物的示例跟踪,以及来自我的NGINX错误日志的示例。我该如何调整以保持服务器打开足够长的时间来处理此请求。

enter image description here

2019/10/02 10:59:25 [error] 10270#10270: *5 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: XXX, server: X.net, request: "GET /?km_source=blog HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock:", host: "X.net", referrer: "https://www.X.net/"
2019/10/02 11:00:42 [error] 10270#10270: *34 upstream timed out (110: Connection timed out) while reading response header from upstream, client: XXX, server: XXX.net, request: "GET /wc-api/v2/orders?status=processing&page=10&filter%5Blimit%5D=100&consumer_key=ck_XXX&consumer_secret=cs_XXX HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock", host: "X.net"
2019/10/02 11:07:53 [error] 13021#13021: *62 upstream timed out (110: Connection timed out) while reading response header from upstream, client: XXX, server: XXX.net, request: "GET /wc-api/v2/orders?status=processing&page=1&filter%5Blimit%5D=100&consumer_key=ck_XXX&consumer_secret=cs_XXX HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock", host: "X.net"
2019/10/02 11:13:45 [error] 15270#15270: *66 upstream timed out (110: Connection timed out) while reading response header from upstream, client: XXX, server: XXX.net, request: "GET /wc-api/v2/orders?status=processing&page=1&filter%5Blimit%5D=100&consumer_key=ck_XXX&consumer_secret=cs_XXX HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock", host: "XXX.net"
2019/10/02 11:15:44 [error] 16010#16010: *79 upstream timed out (110: Connection timed out) while reading response header from upstream, client: XXX, server: X.net, request: "GET /wc-api/v2/orders?status=processing&page=1&filter%5Blimit%5D=100&consumer_key=ck_XXX&consumer_secret=cs_XXX HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock", host: "X.net"

wordpress woocommerce woocommerce-rest-api
1个回答
0
投票

我注意到的第一个问题是,当过滤器应传递3时,它们仅传递2个变量。

add_filter( "woocommerce_rest_pre_insert_shop_order", "remove_user_agent_from_rest_api", 10, 3 );

应该这样做。

© www.soinside.com 2019 - 2024. All rights reserved.