-
Notifications
You must be signed in to change notification settings - Fork 1.1k
JdbcOperationsSessionRepository: deserialize lazily #1133
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
Conversation
The same solution could be applied to RedisOperationsSessionRepository too (I can do that if this approach is deemed acceptable) |
@vpavic what do you think? |
Thanks for the PR @candrews, we'll review and consider this for |
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.
This is something we'd like to get merged in one of the 2.1.0
milestones. I've left one comment on what I believe could be simplified.
Other than that, could you please:
- rebase on the current
master
- provide some unit tests that verified the new behavior
@@ -757,7 +800,7 @@ public void setAttribute(String attributeName, Object attributeValue) { | |||
? oldDeltaValue | |||
: DeltaValue.UPDATED); | |||
} | |||
this.delegate.setAttribute(attributeName, attributeValue); | |||
this.delegate.setAttribute(attributeName, constantSupplier(attributeValue)); |
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.
Is this really necessary? I think we could set attribute here as is, define our own Supplier
and use it in SessionResultSetExtractor
. JdbcSession#getAttribute
would then test if the attribute is instance of the supplier we defined and if yes execute #get
on it. That would reduce the impact and simplify things.
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.
I initially thought of that approach as well, but decided not to go with it. My reasons are:
- I believe
instanceof
checking is generally discouraged in favor of polymorphism (which is what I ended up doing) - That would prohibit the storage of instances of that special class (as doing so would result in unintended behavior)
Would you still like me to go ahead with that approach?
Instead of deserializing all of the session attributes as they are read from the database, deserialize as getAttribute(String) requests them. For applications which store a lot of data in the session but only use some of it for each requests, this change results in a lot less time being spent doing deserialization of objects that won't be used. For other applications, no harm is done.
236b88e
to
5cb6ac1
Compare
✔️
I'm having a bit of trouble with that. |
Also, it occurs to me that the existing integration tests (which pass) show that this change doesn't break anything. |
Thanks for the update @candrews.
You could look into supplying a custom
We are introducing a new behavior here, and we should verify that in our tests. |
That was my first thought, too, but I can't figure out a way to make that happen.
|
Instead of deserializing all of the session attributes as they are read from the database, deserialize as #getAttribute requests them. See: #1133
Instead of deserializing all of the session attributes as they are read from the database, deserialize as getAttribute(String) requests them.
For applications which store a lot of data in the session but only use some of it for each requests, this change results in a lot less time being spent doing deserialization of objects that won't be used.
For other applications, no harm is done.