Attempt to preserve causal relation of join and quit events

Affects issues:
- Possibly fixed #2578
This commit is contained in:
Aurora Lahtela 2022-08-31 08:51:54 +03:00
parent 8d2b4acb41
commit 9d7684e3fb
3 changed files with 15 additions and 3 deletions

View File

@ -90,10 +90,13 @@ public class SessionCache {
* @return Optional: ended session. Recipients of this object should decide if it needs to be saved.
*/
public Optional<FinishedSession> endSession(UUID playerUUID, long time, ActiveSession activeSession) {
if (activeSession == null || activeSession.getStart() > time) {
if (activeSession == null) {
return Optional.empty();
}
ACTIVE_SESSIONS.remove(playerUUID);
if (activeSession.getStart() > time) {
return Optional.empty();
}
return Optional.of(activeSession.toFinishedSession(time));
}

View File

@ -80,12 +80,13 @@ public class PlayerJoinEventConsumer {
}
public void onJoinGameServer(PlayerJoin join) {
Optional<FinishedSession> interruptedSession = cacheActiveSession(join);
processing.submitCritical(() -> {
storeWorldInformation(join);
storeGamePlayer(join)
.thenRunAsync(() -> {
storeJoinAddress(join);
cacheActiveSession(join).ifPresent(this::storeInterruptedSession);
interruptedSession.ifPresent(this::storeInterruptedSession);
storeGeolocation(join);
storeOperatorStatus(join);
storeNickname(join);
@ -96,9 +97,9 @@ public class PlayerJoinEventConsumer {
}
public void onJoinProxyServer(PlayerJoin join) {
cacheActiveSession(join);
processing.submitCritical(() -> storeProxyPlayer(join)
.thenRunAsync(() -> {
cacheActiveSession(join);
storeGeolocation(join);
updatePlayerDataExtensionValues(join);
updateExport(join);

View File

@ -22,6 +22,7 @@ import com.djrapitops.plan.extension.ExtensionSvc;
import com.djrapitops.plan.gathering.cache.JoinAddressCache;
import com.djrapitops.plan.gathering.cache.NicknameCache;
import com.djrapitops.plan.gathering.cache.SessionCache;
import com.djrapitops.plan.gathering.domain.ActiveSession;
import com.djrapitops.plan.gathering.domain.FinishedSession;
import com.djrapitops.plan.gathering.domain.event.PlayerLeave;
import com.djrapitops.plan.processing.Processing;
@ -67,6 +68,13 @@ public class PlayerLeaveEventConsumer {
}
public void onLeaveGameServer(PlayerLeave leave) {
Optional<ActiveSession> activeSession = SessionCache.getCachedSession(leave.getPlayerUUID());
if (activeSession.isEmpty()) {
// Quit event processed before Join event, delay processing
processing.submitCritical(() -> onLeaveGameServer(leave));
return;
}
endSession(leave).ifPresent(this::storeFinishedSession);
storeBanStatus(leave);
updateExport(leave);