Merge branch 'trunk' into update/auto-insert-mini-cart-into-tt2

This commit is contained in:
Tom Cafferkey 2023-12-14 15:48:59 +00:00 committed by GitHub
commit b72d9e341f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 207 additions and 2 deletions

View File

@ -51,3 +51,11 @@ jobs:
with: with:
name: performance-results name: performance-results
path: ${{ env.WP_ARTIFACTS_PATH }}/*.performance-results*.json path: ${{ env.WP_ARTIFACTS_PATH }}/*.performance-results*.json
- name: Publish performance results
if: github.event_name == 'push'
env:
CODEVITALS_PROJECT_TOKEN: ${{ secrets.CODEVITALS_PROJECT_TOKEN }}
run: |
COMMITTED_AT=$(git show -s $GITHUB_SHA --format="%cI")
cd tools/compare-perf && pnpm run log $CODEVITALS_PROJECT_TOKEN trunk $GITHUB_SHA 19f3d0884617d7ecdcf37664f648a51e2987cada $COMMITTED_AT

View File

@ -107,18 +107,24 @@
<rule ref="Generic.Arrays.DisallowShortArraySyntax.Found"> <rule ref="Generic.Arrays.DisallowShortArraySyntax.Found">
<exclude-pattern>src/Internal/Admin/</exclude-pattern> <exclude-pattern>src/Internal/Admin/</exclude-pattern>
<exclude-pattern>src/Admin/</exclude-pattern> <exclude-pattern>src/Admin/</exclude-pattern>
<exclude-pattern>src/Blocks/</exclude-pattern>
<exclude-pattern>src/StoreApi/</exclude-pattern>
</rule> </rule>
<!-- Temporary --> <!-- Temporary -->
<rule ref="WooCommerce.Functions.InternalInjectionMethod.MissingFinal"> <rule ref="WooCommerce.Functions.InternalInjectionMethod.MissingFinal">
<exclude-pattern>src/Internal/Admin/</exclude-pattern> <exclude-pattern>src/Internal/Admin/</exclude-pattern>
<exclude-pattern>src/Admin/</exclude-pattern> <exclude-pattern>src/Admin/</exclude-pattern>
<exclude-pattern>src/Blocks/</exclude-pattern>
<exclude-pattern>src/StoreApi/</exclude-pattern>
</rule> </rule>
<!-- Temporary --> <!-- Temporary -->
<rule ref="WooCommerce.Functions.InternalInjectionMethod.MissingInternalTag"> <rule ref="WooCommerce.Functions.InternalInjectionMethod.MissingInternalTag">
<exclude-pattern>src/Internal/Admin/</exclude-pattern> <exclude-pattern>src/Internal/Admin/</exclude-pattern>
<exclude-pattern>src/Admin/</exclude-pattern> <exclude-pattern>src/Admin/</exclude-pattern>
<exclude-pattern>src/Blocks/</exclude-pattern>
<exclude-pattern>src/StoreApi/</exclude-pattern>
</rule> </rule>
<!-- Temporary --> <!-- Temporary -->

View File

@ -0,0 +1,4 @@
Significance: minor
Type: update
Add InternalInjection sniff exceptions for blocks

View File

@ -0,0 +1,4 @@
Significance: patch
Type: fix
Delete trashed orders after `EMPTY_TRASH_DAYS` as defined by WordPress (HPOS)

View File

@ -80,6 +80,13 @@ class DataSynchronizer implements BatchProcessorInterface {
*/ */
private $error_logger; private $error_logger;
/**
* The instance of the LegacyProxy object to use.
*
* @var LegacyProxy
*/
private $legacy_proxy;
/** /**
* The order cache controller. * The order cache controller.
* *
@ -103,6 +110,7 @@ class DataSynchronizer implements BatchProcessorInterface {
self::add_action( 'woocommerce_refund_created', array( $this, 'handle_updated_order' ), 100 ); self::add_action( 'woocommerce_refund_created', array( $this, 'handle_updated_order' ), 100 );
self::add_action( 'woocommerce_update_order', array( $this, 'handle_updated_order' ), 100 ); self::add_action( 'woocommerce_update_order', array( $this, 'handle_updated_order' ), 100 );
self::add_action( 'wp_scheduled_auto_draft_delete', array( $this, 'delete_auto_draft_orders' ), 9 ); self::add_action( 'wp_scheduled_auto_draft_delete', array( $this, 'delete_auto_draft_orders' ), 9 );
self::add_action( 'wp_scheduled_delete', array( $this, 'delete_trashed_orders' ), 9 );
self::add_filter( 'updated_option', array( $this, 'process_updated_option' ), 999, 3 ); self::add_filter( 'updated_option', array( $this, 'process_updated_option' ), 999, 3 );
self::add_filter( 'added_option', array( $this, 'process_added_option' ), 999, 2 ); self::add_filter( 'added_option', array( $this, 'process_added_option' ), 999, 2 );
self::add_filter( 'deleted_option', array( $this, 'process_deleted_option' ), 999 ); self::add_filter( 'deleted_option', array( $this, 'process_deleted_option' ), 999 );
@ -136,6 +144,7 @@ class DataSynchronizer implements BatchProcessorInterface {
$this->data_store = $data_store; $this->data_store = $data_store;
$this->database_util = $database_util; $this->database_util = $database_util;
$this->posts_to_cot_migrator = $posts_to_cot_migrator; $this->posts_to_cot_migrator = $posts_to_cot_migrator;
$this->legacy_proxy = $legacy_proxy;
$this->error_logger = $legacy_proxy->call_function( 'wc_get_logger' ); $this->error_logger = $legacy_proxy->call_function( 'wc_get_logger' );
$this->order_cache_controller = $order_cache_controller; $this->order_cache_controller = $order_cache_controller;
$this->batch_processing_controller = $batch_processing_controller; $this->batch_processing_controller = $batch_processing_controller;
@ -966,6 +975,41 @@ ORDER BY orders.id ASC
do_action( 'woocommerce_scheduled_auto_draft_delete' ); do_action( 'woocommerce_scheduled_auto_draft_delete' );
} }
/**
* Handles deletion of trashed orders after `EMPTY_TRASH_DAYS` as defined by WordPress.
*
* @since 8.5.0
*
* @return void
*/
private function delete_trashed_orders() {
if ( ! $this->custom_orders_table_is_authoritative() ) {
return;
}
$delete_timestamp = $this->legacy_proxy->call_function( 'time' ) - ( DAY_IN_SECONDS * EMPTY_TRASH_DAYS );
$args = array(
'status' => 'trash',
'limit' => self::ORDERS_SYNC_BATCH_SIZE,
'date_modified' => '<' . $delete_timestamp,
);
$orders = wc_get_orders( $args );
if ( ! $orders || ! is_array( $orders ) ) {
return;
}
foreach ( $orders as $order ) {
if ( $order->get_status() !== 'trash' ) {
continue;
}
if ( $order->get_date_modified()->getTimestamp() >= $delete_timestamp ) {
continue;
}
$order->delete( true );
}
}
/** /**
* Handle the 'woocommerce_feature_description_tip' filter. * Handle the 'woocommerce_feature_description_tip' filter.
* *

View File

@ -25,13 +25,18 @@ class DataSynchronizerTests extends HposTestCase {
*/ */
public function setUp(): void { public function setUp(): void {
parent::setUp(); parent::setUp();
$this->reset_legacy_proxy_mocks();
$container = wc_get_container();
$container->reset_all_resolved();
// Remove the Test Suites use of temporary tables https://wordpress.stackexchange.com/a/220308. // Remove the Test Suites use of temporary tables https://wordpress.stackexchange.com/a/220308.
remove_filter( 'query', array( $this, '_create_temporary_tables' ) ); remove_filter( 'query', array( $this, '_create_temporary_tables' ) );
remove_filter( 'query', array( $this, '_drop_temporary_tables' ) ); remove_filter( 'query', array( $this, '_drop_temporary_tables' ) );
OrderHelper::delete_order_custom_tables(); // We need this since non-temporary tables won't drop automatically. OrderHelper::delete_order_custom_tables(); // We need this since non-temporary tables won't drop automatically.
OrderHelper::create_order_custom_table_if_not_exist(); OrderHelper::create_order_custom_table_if_not_exist();
OrderHelper::toggle_cot_feature_and_usage( false ); OrderHelper::toggle_cot_feature_and_usage( false );
$this->sut = wc_get_container()->get( DataSynchronizer::class ); $this->sut = $container->get( DataSynchronizer::class );
} }
/** /**
@ -530,6 +535,53 @@ class DataSynchronizerTests extends HposTestCase {
$this->assertNotContains( $order1->get_id(), $orders ); $this->assertNotContains( $order1->get_id(), $orders );
} }
/**
* Test that trashed orders are deleted after the time set in `EMPTY_TRASH_DAYS`.
*/
public function test_trashed_order_deletion(): void {
$this->toggle_cot_authoritative( true );
$this->disable_cot_sync();
$order = new WC_Order();
$order->save();
// Ensure the placeholder post is there.
$placeholder = get_post( $order->get_id() );
$this->assertEquals( $order->get_id(), $placeholder->ID );
// Trashed orders should be deleted by the collection mechanism.
$order->get_data_store()->delete( $order );
$this->assertEquals( $order->get_status(), 'trash' );
$order->save();
// Run scheduled deletion.
do_action( 'wp_scheduled_delete' ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.HookCommentWrongStyle
// Refresh order and ensure it's *not* gone.
$order = wc_get_order( $order->get_id() );
$this->assertNotNull( $order );
// Time-travel into the future so that the time required to delete a trashed order has passed.
$this->register_legacy_proxy_function_mocks(
array(
'time' => function() {
return time() + DAY_IN_SECONDS * EMPTY_TRASH_DAYS + 1;
},
)
);
// Run scheduled deletion.
do_action( 'wp_scheduled_delete' ); // phpcs:ignore WooCommerce.Commenting.CommentHooks.HookCommentWrongStyle
// Ensure the placeholder post is gone.
$placeholder = get_post( $order->get_id() );
$this->assertNull( $placeholder );
// Refresh order and ensure it's gone.
$order = wc_get_order( $order->get_id() );
$this->assertFalse( $order );
}
/** /**
* @testDox When HPOS is enabled, the custom orders table is created. * @testDox When HPOS is enabled, the custom orders table is created.
*/ */

View File

@ -0,0 +1,86 @@
#!/usr/bin/env node
/* eslint-disable no-console */
const fs = require( 'fs' );
const path = require( 'path' );
const https = require( 'https' );
const [ token, branch, hash, baseHash, timestamp ] = process.argv.slice( 2 );
const resultsFiles = [
{
file: 'editor.performance-results.json',
metricsPrefix: 'editor-',
},
];
const performanceResults = resultsFiles.map( ( { file } ) =>
JSON.parse(
fs.readFileSync(
path.join( process.env.WP_ARTIFACTS_PATH, file ),
'utf8'
)
)
);
const data = new TextEncoder().encode(
JSON.stringify( {
branch,
hash,
baseHash,
timestamp,
metrics: resultsFiles.reduce( ( result, { metricsPrefix }, index ) => {
return {
...result,
...Object.fromEntries(
Object.entries(
performanceResults[ index ][ hash ] ?? {}
).map( ( [ key, value ] ) => [
metricsPrefix + key,
value,
] )
),
};
}, {} ),
baseMetrics: resultsFiles.reduce(
( result, { metricsPrefix }, index ) => {
return {
...result,
...Object.fromEntries(
Object.entries(
performanceResults[ index ][ baseHash ] ?? {}
).map( ( [ key, value ] ) => [
metricsPrefix + key,
value,
] )
),
};
},
{}
),
} )
);
const options = {
hostname: 'www.codevitals.run',
port: 443,
path: '/api/log?token=' + token,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length,
},
};
const req = https.request( options, ( res ) => {
console.log( `statusCode: ${ res.statusCode }` );
res.on( 'data', ( d ) => {
process.stdout.write( d );
} );
} );
req.on( 'error', ( error ) => {
console.error( error );
} );
req.write( data );
req.end();

View File

@ -7,7 +7,8 @@
"license": "GPLv2", "license": "GPLv2",
"repository": "woocommerce/woocommerce", "repository": "woocommerce/woocommerce",
"scripts": { "scripts": {
"compare": "node index.js" "compare": "node index.js",
"log": "node log-to-codevitals.js"
}, },
"dependencies": { "dependencies": {
"@wordpress/env": "^8.13.0", "@wordpress/env": "^8.13.0",