Do not make entries in "cache_form" when viewing forms that use #ajax['callback'] (Drupal 7 port)

Created on 17 October 2016, about 8 years ago
Updated 13 October 2023, about 1 year ago

Problem/Motivation

The "cache_form" database table (or cache bin) is well known for being a problem point for heavy-traffic sites or in situations where a form is displayed on every page of the site, such as a login or contact block. The problem is that any form that makes use of the #ajax form API property will immediately make two entries in the cache_form table just by viewing the form.

This has lead to run-away tables with millions of entries in some cases. And while more recent solutions like #2091511: Make cache_form expiration configurable, to mitigate runaway cache_form tables β†’ attempt to mitigate the problem, they don't solve the underlying issue that the Drupal form system has a database write operation simply upon view of a form.

This issue has already been solved in Drupal 8 through #2263569: Bypass form caching by default for forms using #ajax. β†’ .

Proposed resolution

Similar to the Drupal 8 issue, make it so that instead of posting to system/ajax, AJAX requests by default post to the current page path. This allows the normal form execution to occur in the same way as the non-Ajax approach. Then detect when the form is built (in drupal_get_form()) if it was done via an Ajax request. If so, process the form normally, but then return the set of Ajax commands directly, ending the page request early.

This eliminates the need for the system/ajax callback entirely, but it is left in place for backwards-compatibility. This suggested change only affects #ajax usages that use "callback", any usages that leverage "path" will still by default trigger the "cache_form" table to be used.

Remaining tasks

Tests are probably still failing.

User interface changes

None.

API changes

Switches the File module to use #ajax['callback'] instead of #ajax['path'], and in the process eliminates the menu callback at "file/ajax".

Data model changes

None.

πŸ› Bug report
Status

Needs work

Version

7.0 ⚰️

Component
FormΒ  β†’

Last updated 3 days ago

Created by

πŸ‡ΊπŸ‡ΈUnited States quicksketch

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¬πŸ‡§United Kingdom mcdruid πŸ‡¬πŸ‡§πŸ‡ͺπŸ‡Ί

    Sorry that this dropped of the radar, but it sound like Needs Work is appropriate based on recent comments.

    It's also not clear (to me) which patch we'd be reviewing now; if there's more than one candidate for review, can we please have a summary of the differences?

  • πŸ‡·πŸ‡ΊRussia skylord

    Reroll #124 for 7.98

Production build 0.71.5 2024