Skip to content

Commit

Permalink
Avoid extraneous call to SessionRespository.findById(...) in SessionR…
Browse files Browse the repository at this point in the history
…epositoryRequestWrapper.commitSession() due to premature cache clearing.
  • Loading branch information
pferraro committed Nov 21, 2020
1 parent 07058c0 commit 92cb240
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,15 @@ private void commitSession() {
}
else {
S session = wrappedSession.getSession();
clearRequestedSessionCache();
SessionRepositoryFilter.this.sessionRepository.save(session);
String sessionId = session.getId();
if (!isRequestedSessionIdValid() || !sessionId.equals(getRequestedSessionId())) {
SessionRepositoryFilter.this.httpSessionIdResolver.setSessionId(this, this.response, sessionId);
try {
SessionRepositoryFilter.this.sessionRepository.save(session);
String sessionId = session.getId();
if (!isRequestedSessionIdValid() || !sessionId.equals(getRequestedSessionId())) {
SessionRepositoryFilter.this.httpSessionIdResolver.setSessionId(this, this.response, sessionId);
}
}
finally {
clearRequestedSessionCache();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1313,8 +1313,8 @@ public void doFilter(HttpServletRequest wrappedRequest, HttpServletResponse wrap
}
});

// 3 invocations expected: initial resolution, after invalidation, after commit
verify(sessionRepository, times(3)).findById(eq(session.getId()));
// 3 invocations expected: initial resolution, after invalidation
verify(sessionRepository, times(2)).findById(eq(session.getId()));
verify(sessionRepository).deleteById(eq(session.getId()));
verify(sessionRepository).createSession();
verify(sessionRepository).save(any());
Expand Down

0 comments on commit 92cb240

Please sign in to comment.