Filter
uncanny-automator-pro
automator_pro_loop_queue_chunk_size
Filters the maximum number of items processed in a single chunk during automation loops.
add_filter( 'automator_pro_loop_queue_chunk_size', $callback, 10, 1 );
Description
Filters the chunk size for processing loop queue items in batches. Developers can adjust this value to prevent MySQL packet size exhaustion, especially with large batches. The default is 1024. Smaller values may improve performance in specific scenarios.
Usage
add_filter( 'automator_pro_loop_queue_chunk_size', 'your_function_name', 10, 1 );
Parameters
-
$this(mixed) - This parameter controls the number of entries saved in a batch to prevent MySQL packet size exhaustion.
Return Value
The filtered value.
Examples
/**
* Filter the chunk size for processing loopable items to prevent MySQL packet size exhaustion.
*
* This example reduces the chunk size to 512 if the process arguments indicate
* a specific type of automation that is known to be memory intensive.
*
* @param int $chunk_size The current chunk size.
* @param array $process_args The arguments passed to the process.
*
* @return int The modified chunk size.
*/
add_filter( 'automator_pro_loop_queue_chunk_size', function( $chunk_size, $process_args ) {
// Check if the process arguments contain specific keys that might indicate a memory-intensive automation.
if ( isset( $process_args['recipe_id'] ) && isset( $process_args['user_id'] ) && 'some_intensive_automation_type' === $process_args['automation_type'] ) {
// Reduce the chunk size if it's a known memory-intensive automation type.
return 512;
}
// Otherwise, return the original chunk size.
return $chunk_size;
}, 10, 2 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
uncanny-automator-pro/src/core/loops/loop/execute.php:227
}
// Spawn a new process since engine is not real-time.
$process = $this->process_registry->spawn_process( $process_id );
// Chunk size controls the numbers of entries that are saved in the batch, preventing mysql packet size exhaustion.
// Use this filter to fix mysql packet size issue. The less the better.
$chunk_size = apply_filters( 'automator_pro_loop_queue_chunk_size', 1024, $this->get_process_args() );
// Skip the process if there are no actions to iterate.
if ( empty( $action_item['items'] ) ) {
throw new Exception( 'Process was skipped because there were no actions to execute.', Automator_Status::COMPLETED );
}
// This method allows as to queue the loopable items in an effecient way without sending the properties into the queue.