Omit changelog from autoloaded option with plugin api data and exclude invalid plugins#2829
Conversation
📝 WalkthroughWalkthroughAdds a force flag and public method to bypass the API cache for fresh addon data; FrmFormApi now prunes non-essential addon fields (changelog, banners) before caching; FrmAddon uses the forced API request when an item_id is present and otherwise falls back to default data. Changes
Sequence Diagram(s)sequenceDiagram
participant Addon as FrmAddon
participant API as FrmFormApi
participant Cache as CacheStore
participant Remote as RemoteAPI
Addon->>API: new FrmFormApi()
Addon->>API: force_api_request()
Note right of API: $force = true
API->>Cache: check cached addons
alt force flag set
API->>Remote: fetch fresh addon data
Remote-->>API: return fresh data
API->>API: reduce_addon_data_before_caching()
API->>Cache: set_cached(reduced data)
else force not set
Cache-->>API: return cached data (if present)
alt cache miss
API->>Remote: fetch remote data
Remote-->>API: return data
API->>API: reduce_addon_data_before_caching()
API->>Cache: set_cached(reduced data)
end
end
API-->>Addon: return addon info (possibly reduced)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@classes/models/FrmAddon.php`:
- Around line 209-216: Guard against an empty API response from
FrmFormApi::get_api_info() before indexing into $plugins[$item_id]; check that
$plugins is a non-empty array and isset($plugins[$item_id]) (or
array_key_exists) and only then set $_data = $plugins[$item_id]; otherwise fall
back to the original data (e.g., the local $data variable or existing source
used before this block) so subsequent uses of $_data['sections'] won't emit
warnings.
🧹 Nitpick comments (1)
classes/models/FrmFormApi.php (1)
389-426: Consider removing banners even when changelog is absent.Right now banners are only removed when
changelogexists. If the goal is payload reduction, unsettingbannersindependently is more consistent.♻️ Suggested tweak
- if ( isset( $addon['changelog'] ) ) { - unset( $addon['changelog'], $addon['banners'] ); - } + if ( isset( $addon['changelog'] ) ) { + unset( $addon['changelog'] ); + } + if ( isset( $addon['banners'] ) ) { + unset( $addon['banners'] ); + }
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@classes/models/FrmFormApi.php`:
- Around line 413-417: Remove the transient debug log call inside the addon
version check: delete the error_log('Omitting ' . $addon['slug'] . ' (Version)')
line within the conditional that checks isset($addon['version']) && '' ===
$addon['version') so the loop continues without emitting debug output; ensure
the surrounding logic in FrmFormApi (the block that references $addon['version']
and $addon['slug']) remains unchanged.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@classes/models/FrmFormApi.php`:
- Around line 441-446: The current check only runs when $addon['categories'] key
exists, so missing categories slip through; update the logic around
$categories_are_empty and the conditional so that absent or falsy
$addon['categories'] is treated as empty (e.g., use empty($addon['categories'])
or !isset(...) || empty(...)) and keep the existing exception for legacy views
by still checking $is_legacy_views (slug 'views'), then return false for addons
with missing/empty categories except the legacy views case.
♻️ Duplicate comments (1)
classes/models/FrmFormApi.php (1)
435-437: Remove debug logging before merge.This debug
error_log()will pollute production logs.🔧 Proposed fix
- if ( isset( $addon['version'] ) && '' === $addon['version'] ) { - error_log( 'Omitting ' . $addon['slug'] . ' (Version)' ); + if ( isset( $addon['version'] ) && '' === $addon['version'] ) { // If version is set but blank, the plugin is not actually live. return false; }
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@classes/models/FrmFormApi.php`:
- Around line 417-419: The current conditional only unsets $addon['banners']
when $addon['changelog'] exists, leaving banners in cache for addons without
changelog; remove the surrounding if (isset($addon['changelog'])) check in
FrmFormApi:: (the block handling $addon) and always call
unset($addon['changelog'], $addon['banners']); directly so both keys are pruned
regardless of which one exists.
♻️ Duplicate comments (1)
classes/models/FrmFormApi.php (1)
440-452: Addons missing thecategorieskey are not excluded.The PR objective states to remove plugins missing categories data, but the current logic only evaluates categories when the key exists. Addons without a
categorieskey will bypass this check and returntrue(included), contradicting the stated objective.🔧 Proposed fix
- if ( isset( $addon['categories'] ) ) { - if ( 'views' === $addon['slug'] ) { - // Legacy views has no categories set, but we should still - // include it in cache since it is a valid add-on. - return true; - } - - $categories_are_empty = ! $addon['categories'] || $addon['categories'] === array( 'Strategy11' ); - - if ( $categories_are_empty ) { - return false; - } - } - - return true; + $is_legacy_views = isset( $addon['slug'] ) && 'views' === $addon['slug']; + $categories = $addon['categories'] ?? array(); + $categories_are_empty = ! $categories || $categories === array( 'Strategy11' ); + + if ( $categories_are_empty && ! $is_legacy_views ) { + return false; + } + + return true;
Related ticket https://secure.helpscout.net/conversation/3202737995/245662
With this update, the stored option data is now ~57kb, down from the previous ~142kb, reducing the size down to 40% of what it was.
What this update does
changelogandbannersfrom the cached data.Pre-release
formidable-6.27.1b.zip
Summary by CodeRabbit
Improvements
Performance
Tests
✏️ Tip: You can customize this high-level summary in your review settings.