Howdy!

Using debug_backtrace() I was able to find out that uc_views.views.inc gets called no matter what. (That in itself is news to me, but not surprising.)

Anyway, this bit of code:

/**
 * Implementation of hook_views_query_substitutions().
 */
function uc_views_views_query_substitutions($view) {
  return array('***CURRENT_CART_ID***' => uc_cart_get_id());
}

calls uc_cart_get_id() which, in its default state, creates a new session cookie ("uc_cart_id") which, when using a reverse proxy cache like Varnish, does not allow pages to be cached at that point.

The quick and easy solution is to throw FALSE into uc_cart_get_id so that a cart is not created if one is not already found. I've tested this, and it seems to work fine, but wanted to get others' feedback and input on this. I can write a patch so you can test it, if you like, but this is pretty quick and dirty. The new function looks thusly:

/**
 * Implementation of hook_views_query_substitutions().
 */
function uc_views_views_query_substitutions($view) {
  return array('***CURRENT_CART_ID***' => uc_cart_get_id(FALSE));
}

On our testing server this change allowed Varnish to cache and serve the pages (until of course an item is added to the cart). Thoughts?

CommentFileSizeAuthor
#7 uc_views-cart_session-1037834-7.patch505 bytesachton

Comments

longwave’s picture

Status: Active » Needs review

Thanks for finding that, never realised that would cause a problem! However, when there's an anonymous user that has no cart, we probably shouldn't try FALSE as the cart id just in case. How about this?

function uc_views_views_query_substitutions($view) {
  if ($cart_id = uc_cart_get_id(FALSE)) {
    return array('***CURRENT_CART_ID***' => $cart_id);
  }
}
torgospizza’s picture

Tested your solution and it seems to work just fine. Thanks!

longwave’s picture

Status: Needs review » Fixed

Committed.

torgospizza’s picture

Woot! Still getting X-Cache: HIT on my end, so things look great. Thanks!

Status: Fixed » Closed (fixed)

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

vacilando’s picture

I spent several hours today trying to find out why Varnish does not cache my anonymous pages. Found that uc_cart_id was set in the session cookie.

Finally found this post, installed the dev version, and the session cookie is finally gone. Thanks!

Could you please publish a new stable version of the module so that more people update their modules?

achton’s picture

StatusFileSize
new505 bytes

Here is a proper patch against current stable version (e.g. for Drush Make).

burningdog’s picture

Version: 6.x-3.1 » 6.x-3.x-dev
Status: Closed (fixed) » Needs work

Thanks - am so glad this has been fixed! I've patched my 6.x-3.1 uc_views with the patch at #7 and now sessions are no longer being set by ubercart on urls that load views.

Can this patch please make it into the stable release?

longwave’s picture

Status: Needs work » Fixed

This is already in -dev and will be in the forthcoming 6.x-3.2.

Status: Fixed » Closed (fixed)

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