Loading
#3632736: logPageErrors() runs one identical query per form error
Closes #3632736
Changes
logPageErrors()callslogPageVisit()once, instead of checkinghasVisitedPage()once per form error.logErrors()updates the existing errors row in place instead of deleting and re-inserting it, and skips the write entirely when the errors haven't changed.alterForm()in the handler no longer checks the visited page twice.
Queries made by logPageErrors(), measured with #3632735 (memoized reads) already in 2.1.x:
| 2.1.x | This MR | |
|---|---|---|
| Errors changed | SELECT, DELETE, INSERT | SELECT ×2, UPDATE |
| Errors unchanged | SELECT, DELETE, INSERT | SELECT ×2 (no write) |
The second SELECT is logErrors() looking up the row that getErrors() already read. Dropping it (by keeping the lid in the errors memo) is left for a follow-up.
Notes
$current_pageis the intended argument forlogPageVisit()here: it's the page whose errors are being logged.- No update hook is needed.
getErrors()andlogErrors()both use the newest errors row, so any older duplicate rows are ignored, and they're removed with the submission's other logs when it's deleted.
Tests
testErrorsRowUpdatedInPlace: the row keeps itslidwhen the errors change, and isn't written again when they don't. Fails on 2.1.x (the row is replaced) and without the "skip if unchanged" check (the row is rewritten).testQueryCountDoesNotGrowWithErrors: guards against the per-error query coming back.testProgressClasses: the progress tracker and progress bar get the right classes (errors, complete, current) from the logged errors.
Also included, as a follow-up to #3632734 (!29 (merged), already merged):
testCurrentPageSkipsPages:getCurrentPage()returns a set current page without evaluating the pages. That early return was half of !29 (merged) and wasn't tested. Fails on the code from before !29 (merged) (buildPages()is called).
Edited by Ryan McVeigh