Have been thinking about this for a while but a conversation in irc just reminded me.

Filters are usually very expensive, one filter that sets 'cache' => 0, prevents all other filters from being cached in check_markup().

Instead of this, we could enforce that cacheable filters run first, then non-cacheable filters run on the cached string.

This way, one badly behaved (or just very tricky) filter, can't spoil things for everyone else.

There is a chance you might want to allow uncacheable filters to run before some others, it would be conceivable to run them on the raw string, then cache based on that processed string, then run other uncacheable filters on the cached string afterwards. I can't think of any that would need to do this but that'd be about as flexible as what we have now, without the overhead of running every filter every time.

Comments

e2thex’s picture

I think this would be awsome, I am currently trying to make a general box embed module, that would let one in embed a box in a content field.

The main issue we run into is as there is no connection from the node to the box, it the box change there is no way to say clear the cache on the node. It would be very nice if we could add the box after the content is cached. We had the same issue in d6 with the node_embed module.

catch’s picture

Priority: Normal » Major
Issue summary: View changes

Bumping to major, now that we have #post_render_cache, and render caching of entities by default, there's less and less reason for this.

wim leers’s picture

Running uncacheable filters last implies we ignore filter order for uncacheable filters, which could break things? And if we allow filters to do things dynamically via #post_render_cache, then why do we need this at all?

I think that's what you're getting at in #2 when you say "less and less reason for this": when #2217877: Text filters should be able to add #attached, #post_render_cache, and cache tags lands, we can just *remove* the ability for filter plugins to indicate they're not cacheable.

Please confirm or clarify :)

catch’s picture

Title: Stop allowing filters to disable caching - run them on cached content instead » Stop allowing filters to disable caching

Yep, better issue title :)

blueminds’s picture

Status: Active » Needs review
StatusFileSize
new4.04 KB

My humble try... please see the patch.

Status: Needs review » Needs work

The last submitted patch, 5: remove_filter_cache_control-1191938-5.patch, failed testing.

wim leers’s picture

Status: Needs work » Needs review
Issue tags: +sprint
Related issues: +#2217877: Text filters should be able to add #attached, #post_render_cache, and cache tags
StatusFileSize
new7.08 KB

#5: thanks for the patch! I independently worked on this too (as part of #2217877: Text filters should be able to add #attached, #post_render_cache, and cache tags), here's my version. Let's help each other get this one to RTBC :)

Status: Needs review » Needs work

The last submitted patch, 7: remove_filter_cacheability-1191938-7.patch, failed testing.

blueminds’s picture

Status: Needs work » Needs review
StatusFileSize
new7.61 KB
new3.57 KB

Rerolled/merged. Let's see if testbot likes.

wim leers’s picture

Status: Needs review » Needs work
+++ b/core/modules/filter/lib/Drupal/filter/Plugin/FilterBase.php
@@ -45,13 +45,6 @@
-  /**

You lost this from #7.

Other than that, it looks good I think :)

blueminds’s picture

Status: Needs work » Needs review
StatusFileSize
new7.9 KB
new596 bytes

Thanks, updated.

wim leers’s picture

+++ b/core/modules/text/lib/Drupal/text/Plugin/Field/FieldType/TextItemBase.php
@@ -74,7 +74,7 @@ public function getCacheData() {
-    if (!$text_processing || filter_format_allowcache($this->get('format')->getValue())) {
+    if (!$text_processing) {

The original code says: "if text processing is disabled, or if text processing is enabled but none of the filters in this text format disables filtering, then generate a cached value".

We've changed that to "if text processing is disabled, then generate a cached value".

This is wrong.

This entire if-statement can go away! :)

wim leers’s picture

Status: Needs review » Needs work
blueminds’s picture

Status: Needs work » Needs review
StatusFileSize
new8.36 KB
new1.33 KB

Updated the patch.

wim leers’s picture

Status: Needs review » Needs work

There are a few more leftovers to be done before I can RTBC this:

  1. The "cache" key should be removed from all filter.format.*.yml files.
  2. filter.schema.yml should be updated also.
  3. FilterFormat still has a $cache property.
  4. FilterInterface still lists cache as an annotation property
  5. FilterDefaultConfigTest is still testing $this->assertEqual($format->get('cache'), 1);, which is passing today because of point 1.

(Discovered while working on #2217877-22: Text filters should be able to add #attached, #post_render_cache, and cache tags.)

blueminds’s picture

StatusFileSize
new4.92 KB
new12.98 KB

Thanks for the list. All removed.

blueminds’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 16: remove_filter_cacheability-1191938-16.patch, failed testing.

blueminds’s picture

Status: Needs work » Needs review
StatusFileSize
new2.32 KB
new15.3 KB

testFilterAdminClearsFilterCache() is probably not needed anymore as well.

wim leers’s picture

Status: Needs review » Needs work

No, #19 is wrong: we are not removing the filter cache here, so you cannot remove the test coverage either.

Since #16 failed, that means this patch introduces a regression somewhere, as demonstrated by the failure in testFilterAdminClearsFilterCache().

Once you've fixed that failure, I can RTBC this :)

blueminds’s picture

Status: Needs work » Needs review
StatusFileSize
new13.74 KB
new774 bytes

Oh, right.

The reason for the fail was that logic in computeFilterCacheId() still accounted for the $format->cache.

blueminds’s picture

bumping this up

wim leers’s picture

Status: Needs review » Closed (duplicate)

#2217877: Text filters should be able to add #attached, #post_render_cache, and cache tags went in, which includes what this patch does and more. I'm very sorry, but this is no longer necessary.