From e24fca4f9682bab968123042291819c13e0ba08a Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Wed, 22 Jul 2026 09:36:43 -0300 Subject: [PATCH 1/5] Remove caching layer --- classes/models/FrmUsage.php | 39 +++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/classes/models/FrmUsage.php b/classes/models/FrmUsage.php index 138ba63136..56265eec8d 100644 --- a/classes/models/FrmUsage.php +++ b/classes/models/FrmUsage.php @@ -603,22 +603,31 @@ private function fields() { * @return array */ private function actions() { - $args = array( - 'post_type' => FrmFormActionsController::$action_post_type, - 'numberposts' => 100, - ); - - $actions = array(); - $saved_actions = FrmDb::check_cache( json_encode( $args ), 'frm_actions', $args, 'get_posts' ); - - foreach ( $saved_actions as $action ) { - $actions[] = array( - 'form_id' => $action->menu_order, - 'type' => $action->post_excerpt, - 'status' => $action->post_status, - 'settings' => FrmAppHelper::maybe_json_decode( $action->post_content ), + $actions = array(); + $offset = 0; + $limit = 100; + + do { + $args = array( + 'post_type' => FrmFormActionsController::$action_post_type, + 'numberposts' => $limit, + 'offset' => $offset, ); - } + $saved_actions = get_posts( $args ); + + foreach ( $saved_actions as $action ) { + $actions[] = array( + 'form_id' => $action->menu_order, + 'type' => $action->post_excerpt, + 'status' => $action->post_status, + 'settings' => FrmAppHelper::maybe_json_decode( $action->post_content ), + ); + unset( $action ); + } + + $offset += $limit; + unset( $saved_actions ); + } while ( count( $actions ) >= $offset ); return $actions; } From ad94163cd87f7cb7e1a4ceaf5ab01037e64ea968 Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Wed, 22 Jul 2026 09:41:25 -0300 Subject: [PATCH 2/5] Call gc_collect_cycles --- classes/models/FrmUsage.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/classes/models/FrmUsage.php b/classes/models/FrmUsage.php index 56265eec8d..e815793880 100644 --- a/classes/models/FrmUsage.php +++ b/classes/models/FrmUsage.php @@ -627,6 +627,8 @@ private function actions() { $offset += $limit; unset( $saved_actions ); + + gc_collect_cycles(); } while ( count( $actions ) >= $offset ); return $actions; From 0075872f990285ec6d6d0826ad69b8316e1d771b Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Wed, 22 Jul 2026 09:45:35 -0300 Subject: [PATCH 3/5] Use a bool instead of using count --- classes/models/FrmUsage.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/classes/models/FrmUsage.php b/classes/models/FrmUsage.php index e815793880..ba6ebac90b 100644 --- a/classes/models/FrmUsage.php +++ b/classes/models/FrmUsage.php @@ -626,10 +626,12 @@ private function actions() { } $offset += $limit; + + $saved_actions_remain = ! empty( $saved_actions ); unset( $saved_actions ); gc_collect_cycles(); - } while ( count( $actions ) >= $offset ); + } while ( $saved_actions_remain ); return $actions; } From d8c65d15024931770afbbddd878d0b9eaed6fb45 Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Wed, 22 Jul 2026 09:51:08 -0300 Subject: [PATCH 4/5] Query for limit + 1 --- classes/models/FrmUsage.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/classes/models/FrmUsage.php b/classes/models/FrmUsage.php index ba6ebac90b..42527e2447 100644 --- a/classes/models/FrmUsage.php +++ b/classes/models/FrmUsage.php @@ -603,18 +603,24 @@ private function fields() { * @return array */ private function actions() { - $actions = array(); - $offset = 0; - $limit = 100; + $actions = array(); + $offset = 0; + $limit = 100; + $limit_plus_one = $limit + 1; do { $args = array( 'post_type' => FrmFormActionsController::$action_post_type, - 'numberposts' => $limit, + 'numberposts' => $limit_plus_one, 'offset' => $offset, ); $saved_actions = get_posts( $args ); + $has_more = count( $saved_actions ) === $limit_plus_one; + if ( $has_more ) { + array_pop( $saved_actions ); + } + foreach ( $saved_actions as $action ) { $actions[] = array( 'form_id' => $action->menu_order, @@ -627,11 +633,10 @@ private function actions() { $offset += $limit; - $saved_actions_remain = ! empty( $saved_actions ); unset( $saved_actions ); gc_collect_cycles(); - } while ( $saved_actions_remain ); + } while ( $has_more ); return $actions; } From ae31c4c5d80913671dd08cf187e443af0072b363 Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Wed, 22 Jul 2026 09:53:37 -0300 Subject: [PATCH 5/5] Run fixers, add comment --- classes/models/FrmUsage.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/classes/models/FrmUsage.php b/classes/models/FrmUsage.php index 42527e2447..df095ffcbb 100644 --- a/classes/models/FrmUsage.php +++ b/classes/models/FrmUsage.php @@ -615,9 +615,10 @@ private function actions() { 'offset' => $offset, ); $saved_actions = get_posts( $args ); + $has_more = count( $saved_actions ) === $limit_plus_one; - $has_more = count( $saved_actions ) === $limit_plus_one; if ( $has_more ) { + // Pop off the last item as it is only queried to determine if there are more results. array_pop( $saved_actions ); }