-
Notifications
You must be signed in to change notification settings - Fork 7
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
Optimize session deletion, recreation, and persistence #10
Conversation
const shouldDelete = session.getCache()._delete; | ||
const shouldRotateSessionKey = c.get("session_key_rotation") === true; | ||
const storeIsCookieStore = store instanceof CookieStore; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original conditionals were logical but a bit challenging for me to grok. I'm a big fan of abstracting conditionals into well named variables. I personally lean towards verbosity over succinctness to make the intention really clear.
That being said, happy to make changes if there is different stylistic preference on how to write these conditionals.
A few other notes:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None of these changes are intended to alter the functionality, just re-organize the code so we aren't unnecessarily updating the session store if we don't need to.
I'll take a look later this week |
Weird. Did you change the I'll run the action again. |
Still failing, I'll check this out in the next couple days. |
Ah, I didn’t realize I needed to pass an encryption key. I’ll remind myself to add this to the testing section of the README |
Okay, think I fixed it! Had a |
Nice! I might play with it a little before I merge it in, but this looks good, thanks! |
Please do, I want to be 100% sure I didn't mess anything up unintentionally! And glad to do it :) |
This work optimizes control flow by only rotating the session key or persisting data if the session is not deleted. The flow before this work would recreate the session key/persist session data every time, even if it would end up being deleted. This is important if storing the session in a database, as that means there is at least one additional round trip. For larger systems this could mean cutting the number of database interactions in half.
Tangential, the
bun dev
script has been split into two to reflect the two types of servers you can run.Before merging I would love it if someone else could test this as well. Not being overly familiar with the library and there being no unit tests makes me nervous I missed something 😅