Skip to content
This repository was archived by the owner on Oct 16, 2019. It is now read-only.

Persist membership cache between requests #53

Merged
merged 3 commits into from
May 15, 2017

Conversation

fphilipe
Copy link
Contributor

The membership cache was being serialized into the user object. It was assumed that the user object was serialized at the end of each request. It turns out that this is not the case. Instead, the user object only gets serialized once, namely after setting the user. This means that the membership cache wasn't working at all between requests.

This commit fixes it by not including the memberships in the serialized user as there's no point in doing so. Instead, after the user object is set up, the memberships hash get retrieved from the user session (warden provides a session object for each scope; if there is none, a new hash is stored in the session) and assigned to the user object. The hash is
then used as before and we get the session serialization from rack for free.

Fixes #52.

The membership cache was being serialized into the user object. It was
assumed that the user object was serialized at the end of each request.
It turns out that this is not the case. Instead, the user object only
gets serialized once, namely after setting the user. This means that the
membership cache wasn't working at all between requests.

This commit fixes it by not including the memberships in the serialized
user as there's no point in doing so. Instead, after the user object is
set up, the memberships hash get retrieved from the user session (warden
provides a session object for each scope; if there is none, a new hash
is stored in the session) and assigned to the user object. The hash is
then used as before and we get the session serialization from rack for
free.

Fixes atmos#52.
@fphilipe fphilipe mentioned this pull request May 13, 2017
@atmos
Copy link
Owner

atmos commented May 14, 2017

Hi @fphilipe,

Any idea what's up with the rack error? I think this was something common in upgrades like 2-3 years ago.

@fphilipe
Copy link
Contributor Author

fphilipe commented May 15, 2017

Hey @atmos. Do you mean rack or rake? 😊 The error in the build is fixed by my other PR #54. I'd rebase this PR on top of the other once that one is merged, or I can combine them into one PR, as you prefer.

Also, I just bumped the patch version number, since this change is completely backwards compatible. The old serialization format that included the memberships field of the struct would still deserialize correctly.

@atmos atmos merged commit 366f9ce into atmos:master May 15, 2017
@atmos
Copy link
Owner

atmos commented May 15, 2017

1.3.2 is live on rubygems.org

@fphilipe fphilipe deleted the fix-membership-cache branch May 16, 2017 07:12
@fphilipe
Copy link
Contributor Author

Thanks @atmos!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Membership data not being cached between requests
2 participants