Merge pull request #23455 from woocommerce/update/23388
During initial product lookup table generation, set an option
This commit is contained in:
commit
b2e428d4cc
|
@ -482,18 +482,18 @@ class WC_Product_Variable_Data_Store_CPT extends WC_Product_Data_Store_CPT imple
|
||||||
$children = $product->get_children();
|
$children = $product->get_children();
|
||||||
|
|
||||||
if ( $children ) {
|
if ( $children ) {
|
||||||
$format = array_fill( 0, count( $children ), '%d' );
|
$format = array_fill( 0, count( $children ), '%d' );
|
||||||
$query_in = '(' . implode( ',', $format ) . ')';
|
$query_in = '(' . implode( ',', $format ) . ')';
|
||||||
$query_args = array( 'stock_status' => $status ) + $children;
|
$query_args = array( 'stock_status' => $status ) + $children;
|
||||||
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
|
// 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(
|
$children_with_status = $wpdb->get_var(
|
||||||
$wpdb->prepare(
|
$wpdb->prepare(
|
||||||
"
|
$query,
|
||||||
SELECT COUNT( product_id )
|
|
||||||
FROM {$wpdb->wc_product_meta_lookup}
|
|
||||||
WHERE stock_status = %s
|
|
||||||
AND product_id IN {$query_in}
|
|
||||||
",
|
|
||||||
$query_args
|
$query_args
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -1302,6 +1302,9 @@ function wc_update_product_lookup_tables() {
|
||||||
WC_Admin_Notices::add_notice( 'regenerating_lookup_table' );
|
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.
|
// Make a row per product in lookup table.
|
||||||
$wpdb->query(
|
$wpdb->query(
|
||||||
"
|
"
|
||||||
|
@ -1324,7 +1327,7 @@ function wc_update_product_lookup_tables() {
|
||||||
'total_sales',
|
'total_sales',
|
||||||
'downloadable',
|
'downloadable',
|
||||||
'virtual',
|
'virtual',
|
||||||
'onsale',
|
'onsale', // When last column is updated, woocommerce_product_lookup_table_is_generating is updated.
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ( $columns as $index => $column ) {
|
foreach ( $columns as $index => $column ) {
|
||||||
|
@ -1482,6 +1485,8 @@ function wc_update_product_lookup_tables_column( $column ) {
|
||||||
$decimals
|
$decimals
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
delete_option( 'woocommerce_product_lookup_table_is_generating' ); // Complete.
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// phpcs:enable WordPress.DB.PreparedSQL.NotPrepared
|
// phpcs:enable WordPress.DB.PreparedSQL.NotPrepared
|
||||||
|
|
Loading…
Reference in New Issue