Problem/Motivation
Within one request, the module reads the same webformnavigation_log data many times:
getErrors()is called fromWebformNavigationHandler::alterForm()(:150),validateForm()(:189),logPageErrors(),logStashedPageErrors(),webformnavigation_preprocess_webform_progress_tracker()(webformnavigation.module:76), andwebformnavigation_preprocess_webform_progress_bar()(:110).hasVisitedPage()runs once per page check, and again insidelogPageVisit().
Because a wizard POST builds the form at least twice (build, then rebuild for the next page), a single step on a large form produced about 10 webformnavigation_log queries in production profiling.
Proposed resolution
Add a per-request memo to WebformNavigationHelper:
- Cache the errors row and the visited-page list per
sid, loading all visited pages for a submission in one query. - Invalidate or update the memo in
logPageVisit(),logErrors()anddeleteSubmissionLogs().
The service is already shared, so a simple property array is enough. A request-scoped cache service isn't needed.
Remaining tasks
- Write the MR.
- Add a kernel test that the memo is invalidated after writes within the same request.
User interface changes
None.
API changes
None. The public method signatures stay the same.
Data model changes
None.
Issue fork webformnavigation-3632735
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,
I added the per-request memo to WebformNavigationHelper.php.
$errorsMemo holds the unserialized latest errors per sid. $visitedPagesMemo holds visited pages per sid, as a [sid][page] => TRUE map.
hasVisitedPage(): the first call for a sid loads every visited page for that submission in one query. After that it only checks the memo.
getErrors(): it runs the errors query once per sid and then reuses the memo for both the full and per-page results.
logPageVisit(): after the insert, it marks the page as visited in the memo.
logErrors(): after the insert, it replaces the memo with the new errors.
deleteSubmissionLogs(): it clears the errors memo. It clears the visited-pages memo too, unless $keep_visited is true.
The memo is keyed by sid only, since a submission ID already identifies its webform.
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 @rmcveigh,
Both the diffs have been applied. Please review the updated MR.
Comment #9
shubhamgoel commentedMay be we can get this one merged first to rebase all the other MRs.
Comment #10
rymcveighComment #12
rymcveighComment #14
rymcveigh@shubhamgoel, I'd love a review of issue #3632737. I rebased that MR, and it is ready to go.
Comment #15
shubhamgoel commentedThanks @rymcveigh. I have added the MR description for this issue.
Sure, I will review the issue #3632737