Filter
uncanny-automator-pro
automator_pro_loop_guard_db_interval
Filters the database interval used to check for infinite loops, preventing automations from running indefinitely.
add_filter( 'automator_pro_loop_guard_db_interval', $callback, 10, 1 );
Description
Filters the interval for database checks within Uncanny Automator Pro's loop guard. Developers can adjust how frequently the loop checks for paused or cancelled states, impacting performance and resource usage. Modifying this value can reduce database queries, but excessively large intervals might delay loop termination in certain scenarios.
Usage
add_filter( 'automator_pro_loop_guard_db_interval', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
/**
* Adjust the database guard interval for Uncanny Automator Pro loops.
*
* This filter allows you to change how often Uncanny Automator Pro checks
* if a loop process should be paused or cancelled. By default, it checks
* every 25 items to save database queries. Increasing this value will
* further reduce database load but may introduce a slight delay in
* responding to pause/cancel commands.
*
* @param int $guard_db_interval The current interval in items. Defaults to 25.
* @return int The modified interval in items.
*/
add_filter( 'automator_pro_loop_guard_db_interval', function( $guard_db_interval ) {
// For very large loops, we might want to increase the interval
// to reduce database overhead further, but ensure it doesn't
// become too long to respond promptly to user actions.
// Let's say we have a very large batch, and we want to check every 50 items.
// We'll also add a condition to make sure we don't exceed a reasonable upper limit,
// for example, 100.
$new_interval = 50;
// Ensure the new interval doesn't exceed a safe maximum
if ( $new_interval > 100 ) {
$new_interval = 100;
}
// You could also dynamically determine this based on other factors,
// like the total number of items in the batch if that information
// were available within the filter's scope.
// For this example, we'll just return a fixed modified value.
return $new_interval;
}, 10, 1 );
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/background-process/entity-actions.php:328
// P1: Checkpoint interval — save batch progress every N items instead of every item.
// At ~32ms/item, 25 items ≈ 800ms max re-work on crash. Reduces serialization by ~90%.
$checkpoint_interval = (int) apply_filters( 'automator_pro_loop_checkpoint_interval', 25 );
// P2: DB guard interval — check is_paused/is_cancelled every N items instead of every item.
// Saves 2 DB queries per skipped item. Max ~800ms delay responding to pause/cancel.
$guard_db_interval = (int) apply_filters( 'automator_pro_loop_guard_db_interval', 25 );
do {
$batch = $this->get_batch();
$item_index = 0;
$_dirty = false; // Track whether batch has unsaved changes.
foreach ( $batch->data as $key => $value ) {