OK, that one took a while to figure out.
I was attempting to determine why my cache hit rate went way down after implementing this module. I'm using Pressflow, which disables sessions and cookies for anonymous users (and therefore allows pages to be cached.) It's because this module generates a new session for anonymous users. I am using this with 'different seed per user'.
When enabling this module and having an anonymous user hit a view with a random seed, we find ourselves in the function views_random_seed_calculate_seed(), which in turn calls _views_random_seed_generate_seed(). These functions use $_SESSION to store the two vars, views_seed_name and views_seed_time - regardless of whether or not the user is authenticated or anonymous. If you are an anonymous user and the session does not already exist (which it does not in my case and for anonymous users), Drupal is kind enough to generate one for you. Once that session is in place, no further caching takes place on any page for anonymous users.
My initial proposal is to force anonymous users to use the stored variable approach to ensure that sessions are not created.
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | generates_sessions_for_anonymous-1344198-11.patch | 2.96 KB | rudins |
| #9 | 1344198-9.patch | 3.13 KB | blake.thompson |
| #7 | 1344198-2.patch | 2.5 KB | jvsteiner |
| #1 | 1344198-1.patch | 2.34 KB | rjbrown99 |
Comments
Comment #1
rjbrown99 commentedFirst shot at a patch is enclosed. Unauthenticated users get the 'same seed per user' mode loaded via a variable with no $_SESSION, and authenticated users with the 'different seed per user' get different random results. I have not tested extensively yet but I will be starting later tonight.
Comment #2
swentel commentedCould you check with #1289734: Different content being displayed for different users - it's kind of trying to fix the same problem - although the title is different and such.
Comment #3
rjbrown99 commentedThat's a similar issue, but the fix does not fix the problem reported here. The fix on #1289734: Different content being displayed for different users will still generate sessions for anonymous users that have the 'different per user' value enabled. My patch here ensures that a session is never created for anonymous users.
Comment #4
swentel commentedHmm, I'll do a review then on both and probably go for some sort of merge - or mark the other one duplicate.
Comment #5
TCRobbert commentedSubscribing
Comment #6
rjbrown99 commentedDon't subscribe to issues, use the follow button at the top.
Comment #7
jvsteiner commentedworked on the patch a bit, working for me with no errors. Unfortunately, although session cookies are now not being generated when its set to use a single seed for all users, I am now seeing duplicate content, which defeats the purpose of this module. patch needs work.
Comment #8
jvsteiner commentedSo I ended up using the patch, as is, since it restores cacheability to the view. I solved the repeat content by using custom php seed code:
this basically uses the current timestamp, rounded to the previous 10 minute mark as the seed. It has the effect of changing the seed every 600 seconds, and can be adjusted. It recaluates every pageload, but reaches the same answer (seed) during each 10 min period.
Comment #9
blake.thompson commentedPatch in #1 seems to have worked for me with a couple adjustments. There was a bug where authenticated users would always generate a new seed if using the same seed for every user, which would reorder results even with views caching enabled. This could also reroll the sorting for anonymous users depending on how pages were being cached. Modified patch from #1 is attached.
Comment #10
killes@www.drop.org commentedThe last patch works great for D7.
Comment #11
rudins commentedFixed patch name and file paths in it.