Caught SQL exception on duplicate insert of user

- Does not treat the root cause, which is two servers not syncronizing for the insert.
- Prevents the error, since the intended SQL has already been executed

Affects issues:
- Fixed #1281
This commit is contained in:
Risto Lahtela 2020-03-26 11:29:52 +02:00
parent 1c1c9fc406
commit 0f8d39d6a2

View File

@ -18,6 +18,7 @@ package com.djrapitops.plan.storage.database.transactions.events;
import com.djrapitops.plan.delivery.webserver.cache.DataID;
import com.djrapitops.plan.delivery.webserver.cache.JSONCache;
import com.djrapitops.plan.exceptions.database.DBOpException;
import com.djrapitops.plan.gathering.cache.SessionCache;
import com.djrapitops.plan.storage.database.queries.DataStoreQueries;
import com.djrapitops.plan.storage.database.queries.PlayerFetchQueries;
@ -52,11 +53,22 @@ public class PlayerRegisterTransaction extends Transaction {
protected void performOperations() {
if (!query(PlayerFetchQueries.isPlayerRegistered(playerUUID))) {
long registerDate = registered.getAsLong();
execute(DataStoreQueries.registerBaseUser(playerUUID, registerDate, playerName));
insertUser(registerDate);
SessionCache.getCachedSession(playerUUID).ifPresent(session -> session.setAsFirstSessionIfMatches(registerDate));
}
execute(DataStoreQueries.updatePlayerName(playerUUID, playerName));
JSONCache.invalidateMatching(DataID.PLAYERS);
}
private void insertUser(long registerDate) {
try {
execute(DataStoreQueries.registerBaseUser(playerUUID, registerDate, playerName));
} catch (DBOpException failed) {
boolean alreadySaved = failed.getMessage().contains("Duplicate entry");
if (!alreadySaved) {
throw failed;
}
}
}
}