Problem/Motivation
WebformNavigationHelper::logPageErrors() (src/WebformNavigationHelper.php:288-317) runs on every validate of a navigation-enabled webform, including every Next, Previous, progress-link click and draft save. Each run:
- SELECTs the latest errors row (
getErrors()). - DELETEs all non-visit rows for the submission (
:294→deleteSubmissionLogs($webform_submission, TRUE)). - For each form error, calls
logPageVisit($webform_submission, $current_page)(:304). The argument is the same$current_pageon every iteration, so this is one identicalhasVisitedPage()SELECT per error. It looks like either$pagewas intended, or the call belongs outside the loop. - INSERTs a new serialized errors row (
:316).
A page with many errors (for example a required composite with many rows) therefore runs 3 + N queries per validate, and each step deletes and re-inserts the error row.
Separately, WebformNavigationHandler::alterForm() calls hasVisitedPage() (:143) and then logPageVisit() (:146), which calls hasVisitedPage() again (:240). That is two identical SELECTs.
Proposed resolution
- Move the
logPageVisit()call out of the per-error loop and call it once. Also confirm whether$pageor$current_pageis the intended argument. - Store at most one errors row per submission and write it with
merge()keyed on(webform_id, sid, operation)instead of DELETE + INSERT. Skip the write when the serialized errors haven't changed. - In
alterForm(), calllogPageVisit()directly, since it already checkshasVisitedPage().
Remaining tasks
- Write the MR.
- Add a test that error logging and the progress-bar error/complete classes behave as before.
- Decide whether to add an update hook that collapses existing duplicate errors rows into one, or simply let the next write replace them.
User interface changes
None.
API changes
None.
Data model changes
There will be at most one errors row per submission. A unique key on (webform_id, sid, operation) can't be added, because the page visited rows legitimately repeat that key. The merge can key on lid found by a lookup, or the module can use a separate errors table.
Issue fork webformnavigation-3632736
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
shubhamgoel commentedHi Team,
The issue has been fixed. Please review and merge the MR https://git.drupalcode.org/project/webformnavigation/-/merge_requests/30....
Comment #5
rymcveighI would like to address this issue before this work to ensure our changes don't introduce regressions. It would be great if you could help review it so that we can progress with this issue.
Comment #6
rymcveighComment #7
rymcveighComment #8
shubhamgoel commentedHi @rymcveigh,
I have rebased the MR and also applied all the feedbacks. Please review and merge the MR.
Comment #9
rymcveighComment #11
rymcveigh