Cache newly created session record

Fixes #1481
This commit is contained in:
AsamK 2024-04-15 19:23:41 +02:00
parent e456d06cb0
commit 71de8e63cc

View file

@ -59,8 +59,11 @@ public class SessionStore implements SignalServiceSessionStore {
public SessionRecord loadSession(SignalProtocolAddress address) { public SessionRecord loadSession(SignalProtocolAddress address) {
final var key = getKey(address); final var key = getKey(address);
try (final var connection = database.getConnection()) { try (final var connection = database.getConnection()) {
final var session = loadSession(connection, key); final var sessionRecord = Objects.requireNonNullElseGet(loadSession(connection, key), SessionRecord::new);
return Objects.requireNonNullElseGet(session, SessionRecord::new); synchronized (cachedSessions) {
cachedSessions.put(key, sessionRecord);
}
return sessionRecord;
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException("Failed read from session store", e); throw new RuntimeException("Failed read from session store", e);
} }
@ -148,7 +151,9 @@ public class SessionStore implements SignalServiceSessionStore {
try (final var connection = database.getConnection()) { try (final var connection = database.getConnection()) {
final var session = loadSession(connection, key); final var session = loadSession(connection, key);
return isActive(session); final var active = isActive(session);
logger.trace("Contains session {}: {} (active: {})", address, session != null, active);
return active;
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException("Failed read from session store", e); throw new RuntimeException("Failed read from session store", e);
} }