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;
- Go to
/node?search=One
- Note that "One" is in the search
<input>
textbox in the exposed filter form block - 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.
Comment | File | Size | Author |
---|---|---|---|
#19 | drupal.org files issues views_910864_0.txt | 916 bytes | Bevan |
#17 | views_910864.patch | 923 bytes | dawehner |
#14 | views_910864.patch | 878 bytes | dagmar |
#10 | 910864.patch | 1.3 KB | Bevan |
#8 | 910864.patch | 1.3 KB | Bevan |
Comments
Comment #1
dawehnerIt would be cool if there would be a update_N hook to set it.
Comment #2
Bilmar CreditAttribution: Bilmar commentedHello,
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!
Comment #3
Bevan CreditAttribution: Bevan commentedtrupal218; 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.
Comment #4
dawehnerI would personally like to have an upgrade path. If noone will have it i will write one.
Comment #5
chuckbar77 CreditAttribution: chuckbar77 commentedThis 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.
Comment #6
chuckbar77 CreditAttribution: chuckbar77 commentedwhoops, 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!
Comment #7
Bevan CreditAttribution: Bevan commenteddereine; 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.
Comment #8
Bevan CreditAttribution: Bevan commentedThe 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;
admin/settings/performance
.Comment #9
dawehnerThanks!
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.
Comment #10
Bevan CreditAttribution: Bevan commentedI 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. (:
Comment #11
dawehnerLooks fine for me.
Comment #12
Bilmar CreditAttribution: Bilmar commentedWorked great - thank you very much!
Comment #13
merlinofchaos CreditAttribution: merlinofchaos commentedTypically 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.
Comment #14
dagmarRerolled due #635336: Remove unused fields from the view introduces views_update_6010() and changes requested in #13.
Comment #15
merlinofchaos CreditAttribution: merlinofchaos commentedBack to RTBC
Comment #16
merlinofchaos CreditAttribution: merlinofchaos commentedJust noticed one other nit:
Should have {} around the table name.
Also just generally on style, I prefer to use $ret = array(); $ret[] = ...; return $ret;
Comment #17
dawehnerUpdated patch based on #16
Comment #18
merlinofchaos CreditAttribution: merlinofchaos commentedThis 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.
Comment #19
Bevan CreditAttribution: Bevan commentedRE: {blocks}; Oops! *blushes*.
Dereine; You had an extra array().
Comment #20
Bevan CreditAttribution: Bevan commentedOops. Cross-posted.
Or perhaps the notices were due to the extra array()?
Comment #21
rburgundy CreditAttribution: rburgundy commented(subscribe)
Comment #22
dawehnerSo this is rtbc now.
Comment #23
Bevan CreditAttribution: Bevan commenteddereine; Does that mean #19 fixed #18? (I haven't had a chance to test it yet.)
Comment #24
dawehnerI thought this errors came from #635336: Remove unused fields from the view
Comment #25
Bevan CreditAttribution: Bevan commentedOkay. Thanks.
Comment #26
Bilmar CreditAttribution: Bilmar commentedThanks for the great work! This works perfectly
Comment #27
Bevan CreditAttribution: Bevan commentedCan we get this in now?
(Bumping priority to get attention from committers)
Comment #28
YK85 CreditAttribution: YK85 commentedsubscribing
Comment #29
merlinofchaos CreditAttribution: merlinofchaos commentedCommitted to all D6 branches;
marking for porting to D7 because I suspect that update_sql() statement needs to be redone for DBTNG.
Comment #30
dawehnerPorted and commited.
Comment #31
Bevan CreditAttribution: Bevan commentedThis 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."
Comment #33
Exploratus CreditAttribution: Exploratus commentedworks nicely
Comment #34
carlos8f CreditAttribution: carlos8f commentedSince #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 :-/