Repository navigation
Use MAX() to find the next field order - #3641
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 27 minutes. View limit details
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 |
|
|
Overall Grade |
Security Reliability Complexity Hygiene |
Code Review Summary
| Analyzer | Status | Updated (UTC) | Details |
|---|---|---|---|
| PHP | Oct 29, 2026 4:12p.m. | Review ↗ | |
| JavaScript | Oct 29, 2026 4:12p.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.
There was a problem hiding this comment.
Approving. Nothing blocking.
Live check (PR branch 119300aba loaded in a WP Playground env, Formidable Lite only):
- The new query is
SELECT MAX(field_order) FROM wp_frm_fields WHERE form_id=3 LIMIT 1. It is valid andFrmDb::get_varstill routes it through$wpdb->prepare;$fieldis a constant, so there is no injection surface. - Empty form:
setup_new_vars()returnsfield_order1 (MAX()gives NULL, NULL+1 = 1), matching the PR description. - After three real
FrmField::create()calls the new fields getfield_order1, 2, 3, and the DB rows read back 1, 2, 3. The per-form result cache doesn't go stale between consecutive adds.
Not exercised: I did not click through the builder UI, and I did not compare against master side by side. The change is one line with the same semantics, so I checked behavior at the helper level. A fields-with-gaps case (e.g. 1, 5, 3, where MAX should return 5) was not cleanly tested because my test edited rows directly and hit the cache; it follows from SQL semantics and the old ORDER BY ... DESC LIMIT 1 gave the same answer.
Other notes:
Psalmis red, but it fails on 912 pre-existingMissingPureAnnotationerrors in files this PR doesn't touch (stripe/, etc.). Not caused by this change. Most other CI jobs showskipping, so the PHPUnit and PHPCS signal is absent here; the one-line diff carries no new lint risk that I can see.- The branch is 7 commits behind
masterbut merges cleanly. - The perf motivation is real but small (a sort over one form's fields, usually tens of rows). That is fine as a cleanup and not worth asking for a benchmark.
Replace the ORDER BY field_order DESC LIMIT 1 lookup in FrmFieldsHelper::setup_new_vars() with MAX(field_order), so MySQL keeps a running max instead of sorting every field in the form. The result is the same, including for a form with no fields (new field gets order 1).
Testing
🤖 Generated with Claude Code