On node build captcha_element_process() is called which disables caching for the page.
This is done even if the form element is not displayed. For example: when having a webform that uses captcha and the webform node is displayed in a view mode that only shows the title and the body (some sort of teaser, but not actually the teaser view mode).
So I think the page cache should be disabled in the rendering process when the field is displayed. If the field is not displayed, the user is trusted, the page is not cached anyway for of the same reason.

Comments

mfernea’s picture

Status: Active » Needs review
StatusFileSize
new2.5 KB

Here is the patch.

fabianx’s picture

Title: Improve cache handling » Improve cache handling for non-displayed captcha's
Priority: Normal » Critical
Issue tags: +Performance
StatusFileSize
new1.86 KB

I 100% agree with the #1 comment here.

I extended the patch to add a comment why the page cache can be disabled very late.

plach’s picture

Status: Needs review » Reviewed & tested by the community

I agree that deferring the choice of disabling page cache to the point where we are sure that the captcha would actually be displayed, unless there's a reason to skip it, is sensible. We still ensure every untrusted user sees the captcha, but we avoid the performance penalty in situations where the captcha would never appear.

wundo’s picture

  • wundo committed cb78754 on 7.x-1.x authored by Fabianx
    Issue #2465113 by mfernea, Fabianx, plach: Improve cache handling for...
wundo’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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