I had a need for Views content caches to be able to be invalidated when nodequeues that views are built on are altered. Nodequeue provides a couple hooks when items are added/removed/reordered in a nodequeue.

I've attached a patch that adds a plugin to add nodequeues as content cache settings.

I'm not totally clear on the 'clause_mode' of 'AND' or 'OR' but I think that in my case I would require 'OR' as 'AND' would mean that both a nodequeue add/remove/reorder AND a nodeapi action would have to happen if I had say node type 'foo' checked in the nodes section of the config along with a nodequeue queue.

Let me know if what I have looks sane. For nodequeue reordering support you need to have Nodequeue release 6.x-2.10 or later or current 6.x-2-dev.

Comments

jaydub’s picture

bumping in the hopes that I can get someone to take a look at the patch...

agileadam’s picture

Hello,
I've tried your patch. While all of the syntax checks out just fine, nothing is happening on the frontend when I add items to, remove items from, or re-order a nodequeue. All of my views Content Cache settings are set to "none" for min/max lifetime. I've tested every way I can think of.

views_content_cache_update_set($subqueue, 'nodequeue'); is executing and returning a 1, but my output on the frontend never changes.

agileadam’s picture

As a followup, I discovered a problem... the parameters for hook_nodequeue_sort_alter() have been reversed in 6.x-2.11. So, for use with nodequeue 2.11:

views_content_cache_nodequeue_sort_alter($sqid, $nodes)

becomes

views_content_cache_nodequeue_sort_alter($nodes, $sqid)

See http://drupal.org/node/1212876#comment-4709402

I'm going to continue testing to see what else might be keeping this from working for me.

jaydub’s picture

Of course the parameter order was reversed :) just my luck. 6.2.11 only came out a few days ago so I haven't had a chance to take a look.

Obviously to support people using new and old versions of nodequeue my patch will have to support either parameter order I would think since it's unrealistic to expect users to be able to upgrade nodequeue and we can't set a module dependency on a specfic module version that I'm aware of.

Did you apply the patch to 6.2.11 only in testing? I haven't had a chance to test my patch against any recent changes to nodequeue so I'll have to make sure your problem isn't solely due to underlying changes in nodequeue.

agileadam’s picture

Hey again,
Unfortunately I never got your code to work 100%. I discovered the parameter swap during my investigation, but didn't devote too much time to figuring out why else it may not be working for me.
If I find some time I'll dig back into it again.
Cheers!

gstout’s picture

Hey all, with the fix,

views_content_cache_nodequeue_sort_alter($sqid, $nodes)
becomes
views_content_cache_nodequeue_sort_alter($nodes, $sqid)

and nodequeue 2.11 this works like a charm. Thank you so much for putting this together and sharing it!

We are now using it on the main top story display at globalpost.com and it's allowing our cache to be significantly more responsive.

Thank You!!

jaydub’s picture

Ok I updated the patch to include logic to try and determine if the Nodequeue sort_alter call is pre 6.2.11 or after. Works locally on both old and new versions of Nodequeue.

agileadam’s picture

Version: 6.x-2.x-dev » 6.x-2.2

Patch from #7 applied cleanly to Dev branch... sorry, I mis-tagged this comment.

soulfroys’s picture

+1 for this! It worked here!

Thank you all!

steven jones’s picture

Patch looks good, but need to get tests passing before I can merge in.

steven jones’s picture

Status: Needs review » Fixed

Thanks so much, merged in 6.x-2.x

Status: Fixed » Closed (fixed)

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

steven jones’s picture

Version: 6.x-2.2 » 7.x-3.x-dev
Status: Closed (fixed) » Patch (to be ported)
jaydub’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new3.29 KB

Got some time and came back around to update my old patch. Attached patch adds nodequeue support to current Drupal 7 views content cache module.

bessone’s picture

tried with views_content_cache 7.x-3.0-alpha2, i get any error but the cache is not flushed.

EDIT: Ops, my fault, I had not seen the option in the View Configuration. Great patch!

mstef’s picture

Getting this warning:

Strict warning: Declaration of views_content_cache_key_nodequeue::options_form() should be compatible with views_content_cache_key::options_form($value, &$handler = NULL) in _registry_check_code() (line 3102 of /var/www/includes/bootstrap.inc).

Seems to be working though -- thanks.

colan’s picture

Category: task » feature
azinck’s picture

Just needed a slight tweak to fix the error in #16

joachim’s picture

Status: Needs review » Reviewed & tested by the community

Patch in #18 works great for me. Thanks!

joachim’s picture

Status: Reviewed & tested by the community » Needs work

Ah on second thoughts, this has issues with exportability:

     'node_only' => array(
       'node_changed' => 0,
     ),
+    'nodequeue' => array(
+      3 => '3',
+      2 => 0,
+      1 => 0,
+    ),
     'og' => array(
       'current' => 0,

That's the diff for my feature. The setting in the view handler should really be using the nodequeue machine name, rather than the local-only nodequeue ID.

zanix’s picture

Issue summary: View changes
StatusFileSize
new3.31 KB

The patch needs a small change to work with Nodequeue 7.x-3.x-dev

$subqueues = nodequeue_load_subqueues_by_queue(nodequeue_get_all_qids());

To

$subqueues = nodequeue_load_subqueues_by_queue(array_keys(nodequeue_get_all_queues()));
rpsu’s picture

Status: Needs work » Needs review
StatusFileSize
new3.99 KB
new1.44 KB

This patch is close to the same as #18, but instead of using internal id it is using nodequeue name as a key to enable exports using nodequeue name instead of internal id.

OR-clause is removed since it broke db-query if nodequeue updates were the only cache invalidation criteria.

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') OR c4 = '6') ORDER BY timestamp DESC' at line 1: SELECT timestamp FROM {views_content_cache} WHERE (() OR c4 = :c4_0) ORDER BY timestamp DESC; Array
(
    [:c4_0] => 6
)
jaydub’s picture

For the OR clause issue, suggest checking out #2407467: views_content_cache_update_get() builds incorrect query possible patch to help with that. Which if it helps, the OR should be added back to the patch.

damienmckenna’s picture

Seeing as it was added to the D6 branch, it should be added to the D7 branch too.

renrhaf’s picture

+1

renrhaf’s picture

@jaydub, @rpsu:
Thanks for your patches, it seems the OR clause if necessary though.
Using the patch you gave in https://www.drupal.org/node/2407467#comment-11535899 fixes the issue properly.

renrhaf’s picture

StatusFileSize
new3.88 KB
new722 bytes
pcambra’s picture

Bear in mind that patches #26 and #27 include the change from #2407467: views_content_cache_update_get() builds incorrect query, those to want to apply the patches separately need to use the one in #22

pcambra’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new3.56 KB

Adding a patch that includes #22 and the clause_mode method to make sure combining diverse criteria to clear cache works but doesn't include #2407467: views_content_cache_update_get() builds incorrect query that needs to be applied independently.

Setting as RTBC

berenddeboer’s picture

Works perfectly, please add this patch.

nironan’s picture

Works like a charm, thanks!

jonhattan’s picture