From 0f8d39d6a27b38b61ae9675e713491d60aa17e34 Mon Sep 17 00:00:00 2001 From: Risto Lahtela <24460436+Rsl1122@users.noreply.github.com> Date: Thu, 26 Mar 2020 11:29:52 +0200 Subject: [PATCH] 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 --- .../events/PlayerRegisterTransaction.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/events/PlayerRegisterTransaction.java b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/events/PlayerRegisterTransaction.java index 7b45a6892..022bef658 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/events/PlayerRegisterTransaction.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/storage/database/transactions/events/PlayerRegisterTransaction.java @@ -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; + } + } + } } \ No newline at end of file