Mirror Session Deletion to Redis Store #57972
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Follow-up to #57562, which started writing session data to Redis with the goal of giving us a chance to analyze real-world usage in advance of a switch to actually start using Redis as the source of truth.
For the most part, that's working, but there are currently a couple of issues with that implementation which both affect the total amount of data being stored, and render that information inaccurate.
First, we aren't deleting old sessions from Redis, so aren't capturing the extent to which users logging out will reduce total data storage. To resolve that, this PR simply extends the
delete_session
method to begin mirroring deletions in Redis the same as we mirror writes.Second, we're actually writing more data than we need to; I mistakenly thought we were going to need to manually serialize and deserialize the Ruby Hashes that our session data is stored in, and chose to do so with
Marshal
, which is much less space-efficient than simply passing the Hash directly to Redis to store. In my local testing, a Hash for a freshly-logged-in session is 168 bytes in memory, but theMarshal
serialization takes 424 bytes.Simplifying the write logic and enabling deletion logic should improve the accuracy of our metrics.
Testing story
Tested locally that logging in, viewing some pages which store information in the session, and then logging back out all work as expected.
PR Checklist: