Problem/Motivation

Within one request, the module reads the same webformnavigation_log data many times:

  • getErrors() is called from WebformNavigationHandler::alterForm() (:150), validateForm() (:189), logPageErrors(), logStashedPageErrors(), webformnavigation_preprocess_webform_progress_tracker() (webformnavigation.module:76), and webformnavigation_preprocess_webform_progress_bar() (:110).
  • hasVisitedPage() runs once per page check, and again inside logPageVisit().

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() and deleteSubmissionLogs().

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.

Command icon 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

rymcveigh created an issue. See original summary.

shubhamgoel made their first commit to this issue’s fork.

shubhamgoel’s picture

Status: Active » Needs review

Hi 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.

rymcveigh’s picture

I 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.

rymcveigh’s picture

Version: 2.0.x-dev » 2.1.x-dev
rymcveigh’s picture

Status: Needs review » Needs work
shubhamgoel’s picture

Status: Needs work » Needs review

Hi @rmcveigh,

Both the diffs have been applied. Please review the updated MR.

shubhamgoel’s picture

May be we can get this one merged first to rebase all the other MRs.

rymcveigh’s picture

Status: Needs review » Reviewed & tested by the community

rymcveigh’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

rymcveigh’s picture

@shubhamgoel, I'd love a review of issue #3632737. I rebased that MR, and it is ready to go.

shubhamgoel’s picture

Thanks @rymcveigh. I have added the MR description for this issue.

Sure, I will review the issue #3632737

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.