Exposed filter block info arrays do not have a cache parameter, and therefore default to BLOCK_CACHE_PER_ROLE — the default for the cache column of the {blocks} table.

Exposed filters, by their very nature, are difficult to cache reasonably, and probably should not be cached by default.

An easily reproducible bug resulting from this with a view with a text "contains" exposed filter (key "search") as a block on all pages;

  1. Go to /node?search=One
  2. Note that "One" is in the search <input> textbox in the exposed filter form block
  3. Go to /golf-node?search=Two
  • Expected behaviour: "Two" should be in the search textbox.
  • Actual behaviour: "One" is in the search textbox.

(Block cache probably needs to be enabled at admin/settings/performance.)

The attached patch sets the cache parameter to BLOCK_NO_CACHE for all newly-created exposed filter blocks.

Although an update path is not required for views 3, the SQL to fix this for all exposed filter blocks that already exist is UPDATE blocks SET cache = -1 WHERE module = 'views' AND delta LIKE '-exp-%'.

This probably fixes part or all of #904314: Filters (Exposed Form in a Block) have issues with Block cache: Enabled, and may be duplicate.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

It would be cool if there would be a update_N hook to set it.

Bilmar’s picture

Hello,

I'm not sure what update_N hook is =) but should I wait on the next patch before apply and testing?
Will existing exposed filter as blocks in Views 3 still have the issue without the below command?
UPDATE blocks SET cache = -1 WHERE module = 'views' AND delta LIKE '-exp-%'

Thanks!

Bevan’s picture

trupal218; Existing exposed filter blocks will still have the issue. You should run that SQL
dereine; Views 3 does not have stable versions so upgrade paths are not supported. Though the maintainer may decide to throw this one in away.

dawehner’s picture

Views 3 does not have stable versions so upgrade paths are not supported

I would personally like to have an upgrade path. If noone will have it i will write one.

chuckbar77’s picture

Status: Needs review » Reviewed & tested by the community

This saved me many hours of hair pulling, thanks!

An upgrade path would be sweet (it look me awhile to figure out how to enter the command to make my current exposed filter blocks not cached), but the patch itself looks to do the trick with newly created exposed filter blocks.

chuckbar77’s picture

Status: Reviewed & tested by the community » Needs review

whoops, I accidentally set it to RTBC but it looks like the maintainer would like an upgrade path before committing.
I hope this may find its way into the latest dev in the near future!

Bevan’s picture

Assigned: Unassigned » Bevan
Status: Needs review » Needs work

dereine; I'm sorry. I haven't contributed to views in a while and only just noticed that you are a maintainer. Please accept my apologies. I'll update the patch to include the update hook.

Bevan’s picture

Assigned: Bevan » Unassigned
Status: Needs work » Needs review
FileSize
1.3 KB

The attached patch includes an update path, views_update_6300() — the first update hook for Views 6.x 3.x.

trupal218, and anyone else with exposed filter blocks that caching too-aggressively with views 3, please test this patch, and specifically that running /update.php fixes the issue described in the ticket description for you.

Also;

  • I confirmed that block cache does need to be enabled at admin/settings/performance.
  • I noticed that the bug does not only affect text filters, but also select-type filters.
  • I noted that this bug does not affect the results of the exposed filter's view — only the exposed filter block.
  • In step 3 of the ticket description, I meant "Go to /node?search=Two" instead of "Go to /golf-node?search=Two"
dawehner’s picture

Thanks!

The update code looks fine.

I would suggest here to talk with merlinofchaos to bump the update function number. We want to keep it as parallel as possible over the three different versions.

Bevan’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
1.3 KB

I spoke with merlinofchaos about this. Since it is also a bug in Views 2, it's hook_update number is 6010. The attached patch corrects that. This should be applied to both 6.x-2.x and 6.x-3.x, but not 7.x-3.x.

IMHO this is RTBC. Revert to "Needs Review" if you disagree. (:

dawehner’s picture

Looks fine for me.

Bilmar’s picture

Worked great - thank you very much!

merlinofchaos’s picture

Status: Reviewed & tested by the community » Needs work

Typically I only actually use single quotes to quote strings in queries. I'm not sure if there are any ill effects of using double quotes, but I'd prefer to be consistent.

dagmar’s picture

Status: Needs work » Needs review
FileSize
878 bytes

Rerolled due #635336: Remove unused fields from the view introduces views_update_6010() and changes requested in #13.

merlinofchaos’s picture

Status: Needs review » Reviewed & tested by the community

Back to RTBC

merlinofchaos’s picture

Status: Reviewed & tested by the community » Needs work

Just noticed one other nit:

+  return array(update_sql("UPDATE blocks SET cache = " . BLOCK_NO_CACHE . " WHERE module = 'views' AND delta LIKE '-exp-%'"));

Should have {} around the table name.

Also just generally on style, I prefer to use $ret = array(); $ret[] = ...; return $ret;

dawehner’s picture

Status: Needs work » Needs review
FileSize
923 bytes

Updated patch based on #16

merlinofchaos’s picture

Status: Needs review » Needs work

This causes notices; I think because views are loaded after the update but before schema has happened. It probably just means we need to add some notice protection to the method that compares schema to actual results.

Bevan’s picture

Status: Needs work » Needs review
FileSize
916 bytes

RE: {blocks}; Oops! *blushes*.

Dereine; You had an extra array().

Bevan’s picture

Oops. Cross-posted.

Or perhaps the notices were due to the extra array()?

rburgundy’s picture

(subscribe)

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

So this is rtbc now.

Bevan’s picture

dereine; Does that mean #19 fixed #18? (I haven't had a chance to test it yet.)

dawehner’s picture

I thought this errors came from #635336: Remove unused fields from the view

Bevan’s picture

Okay. Thanks.

Bilmar’s picture

Thanks for the great work! This works perfectly

Bevan’s picture

Priority: Normal » Major

Can we get this in now?

(Bumping priority to get attention from committers)

YK85’s picture

subscribing

merlinofchaos’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed to all D6 branches;

marking for porting to D7 because I suspect that update_sql() statement needs to be redone for DBTNG.

dawehner’s picture

Status: Patch (to be ported) » Fixed

Ported and commited.

Bevan’s picture

This was not a bug in D7 because (IIRC) D7 handles block caching completely differently. I don't remember the details but I do remember checking D7 code and/or trying to reproduce the bug, hence my comment in #10 "This should be applied to both 6.x-2.x and 6.x-3.x, but not 7.x-3.x."

Status: Fixed » Closed (fixed)

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

Exploratus’s picture

works nicely

carlos8f’s picture


/**
 * Correct the cache setting for exposed filter blocks.
 *
 * @see http://drupal.org/node/910864
 */
function views_update_6012() {
  $ret = array();

  // There is only one simple query to run.
  $update = db_update('blocks')
    ->condition('module', 'views')
    ->condition('delta', db_like('-exp-') . '%', 'LIKE')
    ->fields(array('cache' => DRUPAL_NO_CACHE));
  
  return $ret;
}

Since #235673: Changes to block caching mode not caught D7 updates the block cache mode automatically, so these type of updates aren't really necessary. I've backported that patch to D6 but no one's looked at it in ages :-/