Currently, if flags are enabled for anonymous users there is a check on every page to see if the user has created a flag. This forces session_api to create and save session data for this anonymous user. It would be better for caching systems to only create that session data once the user actually flags something.
Note: This issue is the same problem as reported for Flag v6.x at http://drupal.org/node/1095910.
| Comment | File | Size | Author |
|---|---|---|---|
| #21 | flag_sid_global_fix.patch | 613 bytes | quicksketch |
| #7 | flag_reverse_proxy-d6.patch | 2.52 KB | quicksketch |
| #7 | flag_reverse_proxy-d7.patch | 2.56 KB | quicksketch |
| #6 | anon_session-D6-1258764-6.patch | 4.49 KB | gagarine |
| #2 | anon_session-1258764-2.patch | 4.77 KB | trrroy |
Comments
Comment #1
trrroy commentedTo solve this I added an argument in the calls to flag_get_sid(). The new argument gets passed as FALSE to session_api to prevent creating new sessions if one does not exist. Then the argument is passed as TRUE from flag functions which add flags so that the session is created when needed.
Comment #2
trrroy commentedchanging status to 'needs review'
Comment #3
bleen commentedsubscribing
Comment #4
gagarine commentedtracking
The patch works on beta-5 and master branch.
I will try and see if everything is ok...
Edit marked #1095910: Flat 6.x-2.x starts a session on anonymous user loads which is bad for pressflow/varnish as a duplicate no need for one issue for each version.
Comment #5
gagarine commentedThis part become hard to follow, why not just teste if we are anonyme user and returne
Comment #6
gagarine commentedSame patch but for D6
Comment #7
quicksketchThanks for these patches gagarine and trrroy! I'm trying to figure out why I had put that
flag_set_sid()inflag_init(), because I can't figure out any negative consequence of removing it (or commenting it out as you did in your patches).I've revised these patches so that they're a little easier to follow and require fewer changes. I'm guessing that you set the default $create parameter to TRUE because you wanted to match the session_api_get_sid() function signature, but setting the $create parameter to default to FALSE in Flag module save us a lot of code changes. The default parameter should be the most common one, so I've flipped the default $create to be FALSE instead. The resulting patch is much smaller because we have fewer changes to make.
I also changed the flag_get_user_flags() approach, instead of wrapping the entire chunk of code in another IF statement, I simply added a 3-line IF statement near the top of the function that bails out if the user doesn't have a session.
Overall, this patch should act identical to yours, I've just changed the way the code is written to make it easier for maintenance in the future (for me at least). Could you review this approach and confirm it still works for your setup? I've tested that the session isn't started unnecessarily as it was previously and everything seems to work well in both D7 and Pressflow.
Comment #8
BenK commentedSubscribing
Comment #9
bastnic commentedsubscribe
Comment #10
trrroy commentedThe D7 patch in #7 didn't work for me against the beta5 or newer versions. The code cleanup sounds good. Thanks quicksketch!
Comment #11
quicksketchCould you clarify, "didn't work"? What's the behavior you're expecting and what is Flag module doing incorrectly after applying the patch?
Comment #12
trrroy commentedI meant the actual patch would not apply. I looked at the line numbers in the patch and they don't seem to line up with the flag.inc file (that's the only one I checked).
Comment #13
quicksketchI've confirmed that the patches apply directly with no fuzz or failed hunks against the 7.x-2.x branch in git. Note that I recently branched off from "master" in Git, you may need to pull down the 7.x-2.x branch (or just do a fresh checkout). I didn't remember to update the dev release to point at the new branch though, but after tonight's repackaging it should be up-to-date also.
Comment #15
trrroy commentedYes, this fix is working for me. Thanks!
Comment #16
quicksketchSuper. Committed to both 2.x branches. Will be in the beta7 release.
Comment #17
ju.ri commentedI just tested the 6.x-dev version and still had problems with varnish and anonymous users.
- Using session_api 6.x-1.4, flags are not set. Anonymous flagging doesn't work at all.
- Using session_api 6.x-1.2, flags are set, but all pages get a cookie and "no-cache, must revalidate", so turns off varnish on all pages
this seems to be a thread on the same problem: http://drupal.org/node/1058960
Comment #18
ralf.strobel commentedSorry to be the buzzkiller once again, but the changes made with this patch break all global flags. The flagged status is no longer reported correctly, and thus no unflag links are being displayed.
The problem is this piece of code added to flag_get_user_flags():
get_flagging_record() calls this function in the context of is_flagged().
For global flags it always passes $uid = 0.
Comment #19
quicksketchDoh, right again ralf.strobel! No worries, this is exactly why we made the beta6 release before committing all these architectural changes.
To fix this problem, we could either check if the flag is global, or we could check the global $user->uid.
Comment #20
quicksketchHm, actually on further thought, perhaps the best way to fix this (at least in an easy to understand way) is simply to remove the conditional altogether. I can't think of any negative consequences this would have, and it should only retrieve global flags and nothing else, since there can't (or shouldn't) ever be a situation where an anonymous user has flagged something without an SID.
Comment #21
quicksketchHow about it?
Comment #22
quicksketchI can't find any problems with the above approach. It will unnecessarily do a query for non-global flags for anonymous users, but overall this is negligible since the page is going to be cached anyway.
Comment #23
quicksketchI've committed the patch in #21. Let's open new issues for any further bugs. I don't like having multiple commits attributed to the same issue number.