When using CLI, run queries without queue
This commit is contained in:
parent
520c517410
commit
062d147b59
|
@ -1296,6 +1296,12 @@ function wc_update_product_lookup_tables_is_running() {
|
||||||
function wc_update_product_lookup_tables() {
|
function wc_update_product_lookup_tables() {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
|
|
||||||
|
$is_cli = defined( 'WP_CLI' ) && WP_CLI;
|
||||||
|
|
||||||
|
if ( ! $is_cli ) {
|
||||||
|
WC_Admin_Notices::add_notice( 'regenerating_lookup_table' );
|
||||||
|
}
|
||||||
|
|
||||||
// Make a row per product in lookup table.
|
// Make a row per product in lookup table.
|
||||||
$wpdb->query(
|
$wpdb->query(
|
||||||
"
|
"
|
||||||
|
@ -1308,7 +1314,7 @@ function wc_update_product_lookup_tables() {
|
||||||
"
|
"
|
||||||
);
|
);
|
||||||
|
|
||||||
// Queue update events.
|
// List of column names in the lookup table we need to populate.
|
||||||
$columns = array(
|
$columns = array(
|
||||||
'min_price',
|
'min_price',
|
||||||
'max_price',
|
'max_price',
|
||||||
|
@ -1323,17 +1329,21 @@ function wc_update_product_lookup_tables() {
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ( $columns as $index => $column ) {
|
foreach ( $columns as $index => $column ) {
|
||||||
WC()->queue()->schedule_single(
|
if ( $is_cli ) {
|
||||||
time() + $index,
|
wc_update_product_lookup_tables_column( $column );
|
||||||
'wc_update_product_lookup_tables_column',
|
} else {
|
||||||
array(
|
WC()->queue()->schedule_single(
|
||||||
'column' => $column,
|
time() + $index,
|
||||||
),
|
'wc_update_product_lookup_tables_column',
|
||||||
'wc_update_product_lookup_tables'
|
array(
|
||||||
);
|
'column' => $column,
|
||||||
|
),
|
||||||
|
'wc_update_product_lookup_tables'
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rating counts are serialised so add them gradually using queue.
|
// Rating counts are serialised so they have to be unserialised before populating the lookup table.
|
||||||
$rating_count_rows = $wpdb->get_results(
|
$rating_count_rows = $wpdb->get_results(
|
||||||
"
|
"
|
||||||
SELECT post_id, meta_value FROM {$wpdb->postmeta}
|
SELECT post_id, meta_value FROM {$wpdb->postmeta}
|
||||||
|
@ -1345,23 +1355,25 @@ function wc_update_product_lookup_tables() {
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( $rating_count_rows ) {
|
if ( $rating_count_rows ) {
|
||||||
$rating_count_rows = array_chunk( $rating_count_rows, 50 );
|
if ( $is_cli ) {
|
||||||
$index = 10;
|
wc_update_product_lookup_tables_rating_count( $rating_count_rows );
|
||||||
|
} else {
|
||||||
|
$rating_count_rows = array_chunk( $rating_count_rows, 50 );
|
||||||
|
$index = count( $columns ) + 1;
|
||||||
|
|
||||||
foreach ( $rating_count_rows as $rows ) {
|
foreach ( $rating_count_rows as $rows ) {
|
||||||
WC()->queue()->schedule_single(
|
WC()->queue()->schedule_single(
|
||||||
time() + $index,
|
time() + $index,
|
||||||
'wc_update_product_lookup_tables_rating_count',
|
'wc_update_product_lookup_tables_rating_count',
|
||||||
array(
|
array(
|
||||||
'rows' => $rows,
|
'rows' => $rows,
|
||||||
),
|
),
|
||||||
'wc_update_product_lookup_tables'
|
'wc_update_product_lookup_tables'
|
||||||
);
|
);
|
||||||
|
$index ++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add notice.
|
|
||||||
WC_Admin_Notices::add_notice( 'regenerating_lookup_table' );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue