diff --git a/Plugins/Mineplex.Core/src/mineplex/core/chatsnap/SnapshotRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/chatsnap/SnapshotRepository.java index 28931a432..0872ea51e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/chatsnap/SnapshotRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/chatsnap/SnapshotRepository.java @@ -7,26 +7,13 @@ import java.sql.SQLException; import java.sql.Timestamp; import java.time.ZoneId; import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.UUID; import java.util.concurrent.CompletableFuture; -import java.util.stream.Collectors; -import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; -import com.google.gson.JsonObject; import com.mysql.jdbc.Statement; import mineplex.core.database.MinecraftRepository; -import mineplex.serverdata.Utility; import mineplex.serverdata.database.DBPool; -import mineplex.serverdata.servers.ServerManager; -import redis.clients.jedis.Jedis; -import redis.clients.jedis.JedisPool; /** * Class responsible for publishing snapshots on the website via Redis and a separate Report server. @@ -113,9 +100,9 @@ public class SnapshotRepository extends MinecraftRepository // this allows snapshots to be inserted in batch private void insertSnapshot(Connection connection, PreparedStatement insertSnapshotStatement, int reportId, Snapshot snapshot) throws SQLException { - long messageId = snapshot.getId().orElse((long) -1); + long snapshotId = snapshot.getId().orElse((long) -1); - if (messageId == -1) + if (snapshotId == -1) { insertSnapshotStatement.setInt(1, snapshot.getSenderId()); insertSnapshotStatement.setString(2, _serverName); @@ -127,8 +114,8 @@ public class SnapshotRepository extends MinecraftRepository ResultSet resultSet = insertSnapshotStatement.getGeneratedKeys(); if (resultSet.next()) { - messageId = resultSet.getLong(1); - snapshot._id = messageId; + snapshotId = resultSet.getLong(1); + snapshot._id = snapshotId; } else { @@ -136,23 +123,27 @@ public class SnapshotRepository extends MinecraftRepository } insertSnapshotStatement.close(); - - PreparedStatement insertRecipientStatement = connection.prepareStatement(INSERT_SNAPSHOT_RECIPIENT); - - for (int recipientId : snapshot.getRecipientIds()) - { - insertRecipientStatement.setLong(1, messageId); - insertRecipientStatement.setInt(2, recipientId); - insertRecipientStatement.addBatch(); - } - - insertRecipientStatement.executeBatch(); + insertRecipients(connection, snapshotId, snapshot.getRecipientIds()); } - insertReportSnapshotMapping(connection, reportId, messageId); + insertReportMapping(connection, reportId, snapshotId); } - private void insertReportSnapshotMapping(Connection connection, int reportId, long messageId) throws SQLException + private void insertRecipients(Connection connection, long snapshotId, Collection recipients) throws SQLException + { + PreparedStatement insertRecipientStatement = connection.prepareStatement(INSERT_SNAPSHOT_RECIPIENT); + + for (int recipientId : recipients) + { + insertRecipientStatement.setLong(1, snapshotId); + insertRecipientStatement.setInt(2, recipientId); + insertRecipientStatement.addBatch(); + } + + insertRecipientStatement.executeBatch(); + } + + private void insertReportMapping(Connection connection, int reportId, long messageId) throws SQLException { PreparedStatement reportSnapshotMapping = connection.prepareStatement(INSERT_REPORT_SNAPSHOT_MAPPING); reportSnapshotMapping.setInt(1, reportId);