@@ -83,12 +83,12 @@ public function test_get_batch_returns_never_synced_products_first(): void {
8383 } );
8484
8585 when ( 'wc_get_products ' )->alias ( function ( $ args ) use ( $ never_synced_ids , $ stale_ids ) {
86- if ( ' NOT EXISTS ' === $ args ['meta_query ' ][ 0 ][ ' compare ' ] ) {
86+ if ( ! isset ( $ args ['orderby ' ] ) ) { // Fresh pass (the stale pass sets orderby).
8787 $ available = array_values ( array_diff ( $ never_synced_ids , $ args ['exclude ' ] ) );
8888 return array_slice ( $ available , 0 , $ args ['limit ' ] );
8989 }
9090
91- if ( ' < ' === $ args ['meta_query ' ][ 0 ][ ' compare ' ] ) {
91+ if ( isset ( $ args ['orderby ' ] ) ) { // Stale pass (orders by the processed-at meta).
9292 $ available = array_values ( array_diff ( $ stale_ids , $ args ['exclude ' ] ) );
9393 return array_slice ( $ available , 0 , $ args ['limit ' ] );
9494 }
@@ -119,7 +119,7 @@ public function test_get_batch_respects_limit_with_never_synced_products(): void
119119 } );
120120
121121 when ( 'wc_get_products ' )->alias ( function ( $ args ) use ( $ never_synced_ids ) {
122- if ( ' NOT EXISTS ' === $ args ['meta_query ' ][ 0 ][ ' compare ' ] ) {
122+ if ( ! isset ( $ args ['orderby ' ] ) ) { // Fresh pass (the stale pass sets orderby).
123123 $ available = array_values ( array_diff ( $ never_synced_ids , $ args ['exclude ' ] ) );
124124 return array_slice ( $ available , 0 , $ args ['limit ' ] );
125125 }
@@ -146,7 +146,7 @@ public function test_get_batch_returns_stale_products_when_no_never_synced(): vo
146146 } );
147147
148148 when ( 'wc_get_products ' )->alias ( function ( $ args ) use ( $ stale_product_ids ) {
149- if ( ' < ' === $ args ['meta_query ' ][ 0 ][ ' compare ' ] ) {
149+ if ( isset ( $ args ['orderby ' ] ) ) { // Stale pass (orders by the processed-at meta).
150150 $ available = array_values ( array_diff ( $ stale_product_ids , $ args ['exclude ' ] ) );
151151 return array_slice ( $ available , 0 , $ args ['limit ' ] );
152152 }
@@ -192,12 +192,12 @@ public function test_get_batch_handles_mixed_results(): void {
192192 } );
193193
194194 when ( 'wc_get_products ' )->alias ( function ( $ args ) use ( $ fresh_pool , $ stale_pool ) {
195- if ( ' NOT EXISTS ' === $ args ['meta_query ' ][ 0 ][ ' compare ' ] ) {
195+ if ( ! isset ( $ args ['orderby ' ] ) ) { // Fresh pass (the stale pass sets orderby).
196196 $ available = array_values ( array_diff ( $ fresh_pool , $ args ['exclude ' ] ) );
197197 return array_slice ( $ available , 0 , $ args ['limit ' ] );
198198 }
199199
200- if ( ' < ' === $ args ['meta_query ' ][ 0 ][ ' compare ' ] ) {
200+ if ( isset ( $ args ['orderby ' ] ) ) { // Stale pass (orders by the processed-at meta).
201201 $ available = array_values ( array_diff ( $ stale_pool , $ args ['exclude ' ] ) );
202202 return array_slice ( $ available , 0 , $ args ['limit ' ] );
203203 }
@@ -230,7 +230,7 @@ public function test_get_batch_stops_when_limit_reached_after_fresh_products():
230230 } );
231231
232232 when ( 'wc_get_products ' )->alias ( function ( $ args ) use ( $ fresh_pool ) {
233- if ( ' NOT EXISTS ' === $ args ['meta_query ' ][ 0 ][ ' compare ' ] ) {
233+ if ( ! isset ( $ args ['orderby ' ] ) ) { // Fresh pass (the stale pass sets orderby).
234234 $ available = array_values ( array_diff ( $ fresh_pool , $ args ['exclude ' ] ) );
235235 return array_slice ( $ available , 0 , $ args ['limit ' ] );
236236 }
@@ -273,7 +273,7 @@ public function test_get_batch_terminates_and_skips_unloadable_product_id(): voi
273273 when ( 'wc_get_products ' )->alias ( function ( $ args ) use ( $ fresh_pool , &$ call_count ) {
274274 $ call_count ++;
275275
276- if ( ' NOT EXISTS ' === $ args ['meta_query ' ][ 0 ][ ' compare ' ] ) {
276+ if ( ! isset ( $ args ['orderby ' ] ) ) { // Fresh pass (the stale pass sets orderby).
277277 $ available = array_values ( array_diff ( $ fresh_pool , $ args ['exclude ' ] ) );
278278 return array_slice ( $ available , 0 , $ args ['limit ' ] );
279279 }
@@ -330,7 +330,7 @@ function ( $product ) use ( $products ) {
330330 $ fresh_pool = array ( 1 , 2 , 3 );
331331
332332 when ( 'wc_get_products ' )->alias ( function ( $ args ) use ( $ fresh_pool ) {
333- if ( ' NOT EXISTS ' === $ args ['meta_query ' ][ 0 ][ ' compare ' ] ) {
333+ if ( ! isset ( $ args ['orderby ' ] ) ) { // Fresh pass (the stale pass sets orderby).
334334 $ available = array_values ( array_diff ( $ fresh_pool , $ args ['exclude ' ] ) );
335335 return array_slice ( $ available , 0 , $ args ['limit ' ] );
336336 }
0 commit comments