Merge pull request woocommerce/woocommerce-admin#2521 from woocommerce/fix/action-batch-range
Fix batch queue range bug.
This commit is contained in:
commit
2f4b8272e6
|
@ -515,11 +515,15 @@ class WC_Admin_Reports_Sync {
|
||||||
if ( $range_size > $batch_size ) {
|
if ( $range_size > $batch_size ) {
|
||||||
// If the current batch range is larger than a single batch,
|
// If the current batch range is larger than a single batch,
|
||||||
// split the range into $queue_batch_size chunks.
|
// split the range into $queue_batch_size chunks.
|
||||||
$chunk_size = ceil( $range_size / $batch_size );
|
$chunk_size = (int) ceil( $range_size / $batch_size );
|
||||||
|
|
||||||
for ( $i = 0; $i < $batch_size; $i++ ) {
|
for ( $i = 0; $i < $batch_size; $i++ ) {
|
||||||
$batch_start = $range_start + ( $i * $chunk_size );
|
$batch_start = (int) ( $range_start + ( $i * $chunk_size ) );
|
||||||
$batch_end = min( $range_end, $range_start + ( $chunk_size * ( $i + 1 ) ) - 1 );
|
$batch_end = (int) min( $range_end, $range_start + ( $chunk_size * ( $i + 1 ) ) - 1 );
|
||||||
|
|
||||||
|
if ( $batch_start > $range_end ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
self::queue()->schedule_single(
|
self::queue()->schedule_single(
|
||||||
$action_timestamp,
|
$action_timestamp,
|
||||||
|
|
|
@ -18,7 +18,7 @@ class WC_Tests_Reports_Regenerate_Batching extends WC_REST_Unit_Test_Case {
|
||||||
*
|
*
|
||||||
* @var integer
|
* @var integer
|
||||||
*/
|
*/
|
||||||
public $queue_batch_size = 10;
|
public $queue_batch_size = 100;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Customers batch size.
|
* Customers batch size.
|
||||||
|
@ -79,24 +79,26 @@ class WC_Tests_Reports_Regenerate_Batching extends WC_REST_Unit_Test_Case {
|
||||||
*/
|
*/
|
||||||
public function test_queue_batches_splits_into_batches_correctly() {
|
public function test_queue_batches_splits_into_batches_correctly() {
|
||||||
$num_customers = 1234; // 1234 / 5 = 247 batches
|
$num_customers = 1234; // 1234 / 5 = 247 batches
|
||||||
$num_batches = ceil( $num_customers / $this->customers_batch_size );
|
$num_batches = (int) ceil( $num_customers / $this->customers_batch_size );
|
||||||
|
$chunk_size = (int) ceil( $num_batches / $this->queue_batch_size );
|
||||||
|
$num_chunks = (int) ceil( $num_batches / $chunk_size );
|
||||||
|
|
||||||
WC_Admin_Reports_Sync::queue_batches( 1, $num_batches, WC_Admin_Reports_Sync::CUSTOMERS_IMPORT_BATCH_ACTION );
|
WC_Admin_Reports_Sync::queue_batches( 1, $num_batches, WC_Admin_Reports_Sync::CUSTOMERS_IMPORT_BATCH_ACTION );
|
||||||
|
|
||||||
$this->assertCount( $this->queue_batch_size, $this->queue->actions );
|
$this->assertCount( $num_chunks, $this->queue->actions );
|
||||||
$this->assertArraySubset(
|
$this->assertArraySubset(
|
||||||
array(
|
array(
|
||||||
'hook' => WC_Admin_Reports_Sync::QUEUE_BATCH_ACTION,
|
'hook' => WC_Admin_Reports_Sync::QUEUE_BATCH_ACTION,
|
||||||
'args' => array( 1, 25, WC_Admin_Reports_Sync::CUSTOMERS_IMPORT_BATCH_ACTION ),
|
'args' => array( 1, $chunk_size, WC_Admin_Reports_Sync::CUSTOMERS_IMPORT_BATCH_ACTION ),
|
||||||
),
|
),
|
||||||
$this->queue->actions[0]
|
$this->queue->actions[0]
|
||||||
);
|
);
|
||||||
$this->assertArraySubset(
|
$this->assertArraySubset(
|
||||||
array(
|
array(
|
||||||
'hook' => WC_Admin_Reports_Sync::QUEUE_BATCH_ACTION,
|
'hook' => WC_Admin_Reports_Sync::QUEUE_BATCH_ACTION,
|
||||||
'args' => array( 226, 247, WC_Admin_Reports_Sync::CUSTOMERS_IMPORT_BATCH_ACTION ),
|
'args' => array( 247, 247, WC_Admin_Reports_Sync::CUSTOMERS_IMPORT_BATCH_ACTION ),
|
||||||
),
|
),
|
||||||
$this->queue->actions[ $this->queue_batch_size - 1 ]
|
$this->queue->actions[ $num_chunks - 1 ]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue