Merge pull request #23455 from woocommerce/update/23388

During initial product lookup table generation, set an option
This commit is contained in:
Mike Jolley 2019-04-24 14:51:47 +01:00 committed by GitHub
commit b2e428d4cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 10 deletions

View File

@ -486,14 +486,14 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
$query_in = '(' . implode( ',', $format ) . ')';
$query_args = array( 'stock_status' => $status ) + $children;
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
if ( get_option( 'woocommerce_product_lookup_table_is_generating' ) ) {
$query = "SELECT COUNT( post_id ) FROM {$wpdb->postmeta} WHERE meta_key = '_stock_status' AND meta_value = %s AND post_id IN {$query_in}";
} else {
$query = "SELECT COUNT( product_id ) FROM {$wpdb->wc_product_meta_lookup} WHERE stock_status = %s AND product_id IN {$query_in}";
}
$children_with_status = $wpdb->get_var(
$wpdb->prepare(
"
SELECT COUNT( product_id )
FROM {$wpdb->wc_product_meta_lookup}
WHERE stock_status = %s
AND product_id IN {$query_in}
",
$query,
$query_args
)
);

View File

@ -1302,6 +1302,9 @@ function wc_update_product_lookup_tables() {
WC_Admin_Notices::add_notice( 'regenerating_lookup_table' );
}
// Note that the table is not yet generated.
update_option( 'woocommerce_product_lookup_table_is_generating', true );
// Make a row per product in lookup table.
$wpdb->query(
"
@ -1324,7 +1327,7 @@ function wc_update_product_lookup_tables() {
'total_sales',
'downloadable',
'virtual',
'onsale',
'onsale', // When last column is updated, woocommerce_product_lookup_table_is_generating is updated.
);
foreach ( $columns as $index => $column ) {
@ -1482,6 +1485,8 @@ function wc_update_product_lookup_tables_column( $column ) {
$decimals
)
);
delete_option( 'woocommerce_product_lookup_table_is_generating' ); // Complete.
break;
}
// phpcs:enable WordPress.DB.PreparedSQL.NotPrepared