Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to Session State code #536

Merged
merged 4 commits into from
May 30, 2020

Conversation

JoelSpeed
Copy link
Member

@JoelSpeed JoelSpeed commented May 8, 2020

Description

This is a follow on to #535 that refactors some of the session state code to try and make it easier to manage

Motivation and Context

Improve maintainability of the project

How Has This Been Tested?

Unit tests only

Checklist:

  • My change requires a change to the documentation or CHANGELOG.
  • I have updated the documentation/CHANGELOG accordingly.
  • I have created a feature (non-master) branch for my PR.

@JoelSpeed JoelSpeed mentioned this pull request May 9, 2020
3 tasks

// EncryptInto encrypts the value and stores it back in the string pointer
func (c *Cipher) EncryptInto(s *string) error {
return into(c.Encrypt, s)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JoelSpeed In my size reduction analysis in #523 -- this technique was the biggest culprit of the bloat. Encrypt having an embedded base64 encoding so the result was a valid string that could be in JSON causes 33% size growth.

This is why I experimented shifting to MessagePack (since it supports internal binary data) and relatedly, moving the encryption after the fact to the whole payload, rather than encrypting inside the fields (for speed and to save a few bytes of AES-CFB IV headers present for each distinct inner encryption, especially for smaller non token fields).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack. This PR isn't aimed at improving the size of the sessions at all but is more aimed at improving the code quality. I imagine what will happen is a lot of this may be undone once we implement the MessagePack route, but for now, it shows progression towards better code and eventually the better session sizes

@JoelSpeed JoelSpeed force-pushed the session-state-improvements branch from 05abdcc to 7f69266 Compare May 10, 2020 09:37
@JoelSpeed JoelSpeed marked this pull request as ready for review May 10, 2020 09:37
@JoelSpeed JoelSpeed force-pushed the session-state-improvements branch from 7f69266 to 5ccc72c Compare May 10, 2020 14:27
@loshz loshz removed their request for review May 12, 2020 10:31
Copy link
Member

@steakunderscore steakunderscore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -111,8 +111,9 @@ func newRedisCmdable(opts options.RedisStoreOptions) (Client, error) {
// Save takes a sessions.SessionState and stores the information from it
// to redies, and adds a new ticket cookie on the HTTP response writer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice to get some tests written for this code, but I don't think it should block this change.

@JoelSpeed
Copy link
Member Author

JoelSpeed commented May 23, 2020

@steakunderscore I have rebased as there was a small conflict. I agree, this is under tested, will make an issue to fix this (edit: there's a PR in progress to update the tests, it's not perfect but goes some of the way to getting testing there)

@JoelSpeed JoelSpeed force-pushed the session-state-improvements branch from 6b5ac3e to 1a0945e Compare May 25, 2020 11:51
@steakunderscore steakunderscore merged commit f7b28cb into master May 30, 2020
@steakunderscore steakunderscore deleted the session-state-improvements branch May 30, 2020 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants