Allow caching of draft webform pages

Created on 10 May 2024, about 2 months ago
Updated 14 May 2024, about 1 month ago

Problem/Motivation

Currently, in the webforms that allow drafts the page where the webform is loaded is not cached. This is done here: https://git.drupalcode.org/project/webform/-/blob/6.2.x/src/Element/Webf...

The problem is that there are pages which reference this webform, and the complete page becomes not cacheable which may become a bottleneck in pages with a lot of traffic.

Steps to reproduce

  1. Create a webform that allows draft.
  2. Add that webform to a node through a webform reference field.
  3. Go to the page

At this moment the page becomes not cacheable.

Proposed resolution

Use session cache context instead of max-age / session. It should work because:

- When a webform submission draft is saved, a session is generated storing the webform submissions.
- Most external caching systems like Varnish stops retrieving cached pages when there is a session present

Feature request
Status

RTBC

Version

6.2

Component

Code

Created by

🇪🇸Spain omarlopesino

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @omarlopesino
  • Open on Drupal.org →
    Core: 10.1.4 + Environment: PHP 8.2 & MySQL 8
    last update about 2 months ago
    Waiting for branch to pass
  • Status changed to Needs review about 2 months ago
  • 🇪🇸Spain omarlopesino

    Please review the merge request I've just created, which use session cache context.

    Let me know what do you think, thank you!

  • Open on Drupal.org →
    Core: 10.1.4 + Environment: PHP 8.2 & MySQL 8
    last update about 2 months ago
    Waiting for branch to pass
  • Pipeline finished with Canceled
    about 2 months ago
    Total: 234s
    #169728
  • Pipeline finished with Failed
    about 2 months ago
    #169732
  • Status changed to Needs work about 2 months ago
  • 🇪🇸Spain omarlopesino

    Webform paragraphs drafts are failing in the last pipeline:

    1) Drupal\Tests\webform\Functional\Paragraphs\WebformParagraphsDraftsTest::testParagraphsDrafts
    Behat\Mink\Exception\ExpectationException: The string "A partially-completed form was found. Please complete the remaining portions." was not found anywhere in the HTML response of the current page.

    Checking why it fails.

  • 🇪🇸Spain omarlopesino

    I've noticed:

    1. The session cache context is already added https://git.drupalcode.org/project/webform/-/blob/6.2.x/src/WebformSubmi... . So the current patch needs work as it is only removing the cache invalidation.
    2. The test passes when the webform is added with source entity, but not when it is added without source entity.

    Still checking for solutions.

  • Open on Drupal.org →
    Core: 10.1.4 + Environment: PHP 8.2 & MySQL 8
    last update about 2 months ago
    Waiting for branch to pass
  • Status changed to Needs review about 2 months ago
  • 🇪🇸Spain omarlopesino

    Fixed the MR to only invalidate caches if the submission does not have source entity. Now tests should pass.

  • Pipeline finished with Success
    about 2 months ago
    Total: 2009s
    #171737
  • I've tested it and it works! Response header "Cache-Control:" goes from "must-revalidate, no-cache, private" to "max-age=86400, public". As in tested case, source entity is always used. Anyone that also wants to check this consider any other module or functionality using "\Drupal::service(('page_cache_kill_switch'))->trigger();" may affect. Any case, more opinions & review are preferred i think.

    +1 to RTBC!

  • Status changed to RTBC about 1 month ago
Production build 0.69.0 2024