From f728d988bd1eb7247944db6a80fee39d80761c6a Mon Sep 17 00:00:00 2001 From: Konstantin Obenland Date: Mon, 5 Oct 2026 15:41:07 +0000 Subject: [PATCH] Pattern Translations: Clear runtime caches after each locale. Some patterns exhaust the 512M memory limit while being processed across all locales, so the chunks containing them fail on every run. Clear the runtime caches after each locale rather than after each pattern. Use wp_cache_flush_runtime() rather than resetting object cache internals, which also avoids the deprecation notice for the removed `memcache_debug` property. Log each pattern ID when running in cron, as WP_CLI::log() output isn't captured by Cavalcade. --- .../pattern-translations/includes/cron.php | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/public_html/wp-content/plugins/pattern-translations/includes/cron.php b/public_html/wp-content/plugins/pattern-translations/includes/cron.php index 3871a22e..800d84dc 100644 --- a/public_html/wp-content/plugins/pattern-translations/includes/cron.php +++ b/public_html/wp-content/plugins/pattern-translations/includes/cron.php @@ -99,6 +99,11 @@ function () { foreach ( $pattern_ids as $i => $pattern_id ) { $pattern = Pattern::from_post( get_post( $pattern_id ) ); + if ( wp_doing_cron() ) { + // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- WP_CLI::log() output isn't captured by Cavalcade; this identifies the pattern if the job runs out of memory. + error_log( "Pattern translation import: processing {$pattern_id} ({$pattern->name})." ); + } + if ( defined( 'WP_CLI' ) && WP_CLI ) { WP_CLI::log( "{$i}. Processing {$pattern->name} / '{$pattern->title}'.." ); } @@ -130,10 +135,10 @@ function () { * need to handle. Serving old Translated template is better in this case. */ } - } - // Clear memory-heavy variables after each iteration of Patterns, to avoid object cache memory exhaustion. - clear_memory_heavy_variables(); + // A single pattern across all locales can exhaust memory, so clear after each locale. + clear_memory_heavy_variables(); + } } } add_action( 'pattern_import_translations_to_directory', __NAMESPACE__ . '\pattern_import_translations_to_directory' ); @@ -142,17 +147,12 @@ function () { * Clear caches for memory management. * * @static - * @global \wpdb $wpdb - * @global \WP_Object_Cache $wp_object_cache + * @global \wpdb $wpdb */ function clear_memory_heavy_variables() { - global $wpdb, $wp_object_cache; + global $wpdb; $wpdb->queries = array(); - if ( is_object( $wp_object_cache ) ) { - $wp_object_cache->cache = array(); - $wp_object_cache->group_ops = array(); - $wp_object_cache->memcache_debug = array(); - } + wp_cache_flush_runtime(); }