Skip to content

Commit 1f38a93

Browse files
quaffrwinch
authored andcommitted
Eliminate unnecessary sessionRepository::findById
1 parent e027d20 commit 1f38a93

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

spring-session-core/src/main/java/org/springframework/session/web/http/SessionRepositoryFilter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
* @author Rob Winch
7676
* @author Vedran Pavic
7777
* @author Josh Cummings
78+
* @author Yanming Zhou
7879
* @since 1.0
7980
*/
8081
@Order(SessionRepositoryFilter.DEFAULT_ORDER)
@@ -222,10 +223,11 @@ private void commitSession() {
222223
}
223224
else {
224225
S session = wrappedSession.getSession();
226+
String requestedSessionId = getRequestedSessionId();
225227
clearRequestedSessionCache();
226228
SessionRepositoryFilter.this.sessionRepository.save(session);
227229
String sessionId = session.getId();
228-
if (!isRequestedSessionIdValid() || !sessionId.equals(getRequestedSessionId())) {
230+
if (!isRequestedSessionIdValid() || !sessionId.equals(requestedSessionId)) {
229231
SessionRepositoryFilter.this.httpSessionIdResolver.setSessionId(this, this.response, sessionId);
230232
}
231233
}

spring-session-core/src/test/java/org/springframework/session/web/http/SessionRepositoryFilterTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,8 +1327,8 @@ public void doFilter(HttpServletRequest wrappedRequest, HttpServletResponse wrap
13271327
}
13281328
});
13291329

1330-
// 3 invocations expected: initial resolution, after invalidation, after commit
1331-
verify(sessionRepository, times(3)).findById(eq(session.getId()));
1330+
// 2 invocations expected: initial resolution, after invalidation, after commit
1331+
verify(sessionRepository, times(2)).findById(eq(session.getId()));
13321332
verify(sessionRepository).deleteById(eq(session.getId()));
13331333
verify(sessionRepository).createSession();
13341334
verify(sessionRepository).save(any());

0 commit comments

Comments
 (0)