优化用户session逻辑

This commit is contained in:
imhao183
2019-12-18 09:02:59 +08:00
parent 6acea9b140
commit fe525e9483
3 changed files with 18 additions and 7 deletions
@@ -328,16 +328,27 @@ public class MemorySessionStore implements ISessionsStore {
}
@Override
public Session createUserSession(String username, String clientID, int platform) {
public Session updateOrCreateUserSession(String username, String clientID, int platform) {
LOG.debug("createUserSession for client <{}>, user <{}>", clientID, username);
ClientSession clientSession = new ClientSession(clientID, this);
Session session = databaseStore.getSession(username, clientID, clientSession);
Session session = sessions.get(clientID);
if (session == null) {
session = databaseStore.createSession(username, clientID, clientSession, platform);
if (session == null || !session.username.equals(username)) {
if (session != null && !session.username.equals(username)) {
if (userSessions.get(username) != null) {
userSessions.get(username).remove(clientID);
}
}
ClientSession clientSession = new ClientSession(clientID, this);
session = databaseStore.getSession(username, clientID, clientSession);
if (session == null) {
session = databaseStore.createSession(username, clientID, clientSession, platform);
}
sessions.put(clientID, session);
}
if (session.getDeleted() > 0) {
session.setDeleted(0);
databaseStore.updateSessionDeleted(username, clientID, 0);