Skip to content

Get all form actions for usage tracking#3197

Open
Crabcyborg wants to merge 5 commits into
masterfrom
get_all_form_actions_for_usage_tracking
Open

Get all form actions for usage tracking#3197
Crabcyborg wants to merge 5 commits into
masterfrom
get_all_form_actions_for_usage_tracking

Conversation

@Crabcyborg

@Crabcyborg Crabcyborg commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

It looks like our usage tracking would only send data for 100 form actions. This update uses batches to pull all form actions, 100 at a time.

This is memory sensitive, so I added some unset code and a call to gc_collect_cycles. I also removed our caching layer here, as I think it would just add to memory in most cases since this query isn't really happening in any other code. Without the extra logic, the query is significantly faster as well.

Summary by CodeRabbit

  • Bug Fixes
    • Usage snapshots now capture all available actions, including installations with more than 100 actions.
    • Improved reliability when loading large sets of usage data.

@Crabcyborg Crabcyborg added this to the 6.34 milestone Jul 22, 2026
@Crabcyborg Crabcyborg changed the title Remove caching layer Get all form actions for usage tracking Jul 22, 2026
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

FrmUsage::actions() now retrieves actions in pages of 100 using repeated get_posts() calls and increasing offsets. Retrieved actions retain the existing mapping for form ID, type, status, and decoded settings.

Changes

Usage action collection

Layer / File(s) Summary
Paginate usage actions
classes/models/FrmUsage.php
actions() replaces the single cached fetch with a pagination loop and preserves the existing per-action output mapping.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: fetching all form actions for usage tracking instead of only a cached subset.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch get_all_form_actions_for_usage_tracking

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@deepsource-io

deepsource-io Bot commented Jul 22, 2026

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in ddac8e5...ae31c4c on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
PHP Jul 22, 2026 12:53p.m. Review ↗
JavaScript Jul 22, 2026 12:53p.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
classes/models/FrmUsage.php (2)

611-616: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Disable unused meta and term cache hydration.

This code only reads post columns, not metadata or taxonomies. With multiple queries, leaving these options at their defaults can add unnecessary SQL work per page. Set update_post_meta_cache and update_post_term_cache to false. (developer.wordpress.org)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@classes/models/FrmUsage.php` around lines 611 - 616, Update the `$args` array
used by `get_posts()` in the saved-actions query to set both
`update_post_meta_cache` and `update_post_term_cache` to false, while preserving
the existing post type, limit, and offset settings.

610-630: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add pagination boundary tests.

Cover zero, 100, 101, and more than 200 actions, including non-published statuses and JSON settings, to verify no records are omitted or duplicated.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@classes/models/FrmUsage.php` around lines 610 - 630, The pagination loop
around FrmUsage’s action retrieval must be covered with boundary tests for zero,
100, 101, and more than 200 actions. Include non-published statuses and JSON
settings, then assert every action is returned exactly once with its form_id,
type, status, and decoded settings preserved.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@classes/models/FrmUsage.php`:
- Around line 611-630: Update the $args query configuration in the paginated
action-loading loop to include a deterministic order, such as ordering by ID,
before calling get_posts(). Keep the existing limit, offset, and action
collection behavior unchanged.
- Around line 611-623: Update the $args array used by get_posts() in the saved
actions snapshot to include an explicit post_status filter covering all action
statuses intended for the inventory, including draft and private actions. Keep
the existing pagination and action mapping in the foreach loop unchanged.

---

Nitpick comments:
In `@classes/models/FrmUsage.php`:
- Around line 611-616: Update the `$args` array used by `get_posts()` in the
saved-actions query to set both `update_post_meta_cache` and
`update_post_term_cache` to false, while preserving the existing post type,
limit, and offset settings.
- Around line 610-630: The pagination loop around FrmUsage’s action retrieval
must be covered with boundary tests for zero, 100, 101, and more than 200
actions. Include non-published statuses and JSON settings, then assert every
action is returned exactly once with its form_id, type, status, and decoded
settings preserved.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 561559d8-b73b-4bc9-b1d4-5743f83ec6c7

📥 Commits

Reviewing files that changed from the base of the PR and between ddac8e5 and e24fca4.

📒 Files selected for processing (1)
  • classes/models/FrmUsage.php

Comment on lines +611 to +623
$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 ),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the relevant method and nearby context.
file="classes/models/FrmUsage.php"
wc -l "$file"
sed -n '560,680p' "$file"

# Find the action post type definition and any related status handling.
rg -n "action_post_type|post_status|get_posts\(" classes -g '*.php'

Repository: Strategy11/formidable-forms

Length of output: 10749


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Map the FrmUsage class and inspect the actions() method.
ast-grep outline classes/models/FrmUsage.php --view expanded

# Show the action post type registration and any status-related queries.
rg -n "register_post_type|action_post_type|FrmFormActionsController" classes -g '*.php' -A4 -B4

Repository: Strategy11/formidable-forms

Length of output: 29146


🌐 Web query:

WordPress get_posts default post_status when omitted public non-public post types

💡 Result:

When using the WordPress get_posts() function, if the post_status argument is omitted from the input array, the function automatically assigns a default value based on the specified post_type [1][2][3]. The logic applied within get_posts() is as follows: - If post_type is set to attachment, the default post_status is inherit [1][2][4]. - For all other post types (including the default post_type of post or any other registered custom post type), the default post_status is publish [1][5][4]. This behavior is explicitly defined in the function's source code: php if ( empty( $parsed_args['post_status'] ) ) { $parsed_args['post_status'] = ( 'attachment' === $parsed_args['post_type'] ) ? 'inherit' : 'publish'; } It is important to note that get_posts() ultimately passes these arguments to WP_Query [1][6]. While get_posts() itself defaults to publish (or inherit), WP_Query may internally handle additional statuses—such as private—if the current user has the appropriate capabilities to view them [7][4]. However, the get_posts() function intentionally sets these initial defaults to ensure standard public-facing behavior by default [1][4].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the snapshot payload and how actions() is used.
sed -n '1,220p' classes/models/FrmUsage.php

# Inspect action status defaults/creation paths that show non-published actions exist.
sed -n '460,580p' classes/models/FrmFormAction.php
sed -n '730,820p' classes/models/FrmFormAction.php

Repository: Strategy11/formidable-forms

Length of output: 11172


Include non-published actions in the snapshot. get_posts() defaults to published posts here, so draft/private actions are skipped and the usage payload misses part of the action set. Pass an explicit post_status filter that matches the inventory you want.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@classes/models/FrmUsage.php` around lines 611 - 623, Update the $args array
used by get_posts() in the saved actions snapshot to include an explicit
post_status filter covering all action statuses intended for the inventory,
including draft and private actions. Keep the existing pagination and action
mapping in the foreach loop unchanged.

Comment thread classes/models/FrmUsage.php Outdated
Comment on lines +611 to +630
$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 );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate the relevant file and inspect the surrounding function.
git ls-files 'classes/models/FrmUsage.php'
wc -l classes/models/FrmUsage.php
sed -n '560,660p' classes/models/FrmUsage.php

Repository: Strategy11/formidable-forms

Length of output: 2244


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Search for other get_posts usages in this file to compare ordering/pagination patterns.
rg -n "get_posts\(|orderby|order\s*=>" classes/models/FrmUsage.php

Repository: Strategy11/formidable-forms

Length of output: 209


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the function that contains the paginated query and its surrounding logic.
ast-grep outline classes/models/FrmUsage.php --view expanded

Repository: Strategy11/formidable-forms

Length of output: 1053


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect how FrmUsage::actions() is used to judge impact.
sed -n '1,140p' classes/models/FrmUsage.php

Repository: Strategy11/formidable-forms

Length of output: 3704


Add a deterministic order to this paginated query. get_posts() defaults to date ordering, so offset-based paging can skip or duplicate actions when rows share timestamps or change between batches. Add an explicit order, such as orderby => 'ID', or switch to keyset pagination.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@classes/models/FrmUsage.php` around lines 611 - 630, Update the $args query
configuration in the paginated action-loading loop to include a deterministic
order, such as ordering by ID, before calling get_posts(). Keep the existing
limit, offset, and action collection behavior unchanged.

@Crabcyborg
Crabcyborg requested a review from truongwp July 22, 2026 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant