spring-projects / spring-projects/spring-session
SessionRepositoryFilter.SessionRepositoryRequestWrapper.commitSession() triggers extraneous call to SessionRespository.findById(...)
@eleftherias is already working on this.
Since Nov 27, 2020.
- Dominant language
- Java
- Stars
- 1.9k
- Forks
- 1.2k
- Avg merge
- 4h 27m
- Merged PRs (30d)
- 55
Description
Describe the bug
For a valid session, SessionRepositoryFilter.SessionRepositoryRequestWrapper.commitSession() does the following:
- Clears cached values for references for requestedSessionCache, requestedSession, and requestedSessionId.
- Saves the state of the session
- If the requested session ID is not valid, or if the ID of the session changed from the requested session ID, then the session ID is sent to the client
However, since #1 already cleared the requested session cached values #3 requires a completely redundant call to SessionRepository.findById(...). Depending on the implementation, this can be unnecessarily expensive.
To Reproduce
Use a tracer to detect calls to SessionRepository.findById(...). For a requested session, this is triggered twice, once at the beginning of the request, and again after the session is saved.
Expected behavior
SessionRepository.findById(...) should be considered a potentially expensive operation, and only triggered when necessary. Clearing cached values after determining whether to send the session ID to the client (i.e. in a finally block) would solve the problem.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.