mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-25 18:47:50 +01:00
Refactored PingTable#insertAllPings to an executable
- Renamed some of the new methods
This commit is contained in:
parent
ee0462c1d0
commit
685c58ec42
@ -44,19 +44,20 @@ public class BackupCopyTransaction extends RemoveEverythingTransaction {
|
||||
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
// Clear the database.
|
||||
super.performOperations();
|
||||
|
||||
copyServers();
|
||||
copyUsers();
|
||||
copyWorlds();
|
||||
copyTPS();
|
||||
copyWebUsers();
|
||||
copyPlanServerInformation();
|
||||
copyCommonUserInformation();
|
||||
copyWorldNames();
|
||||
copyTPSData();
|
||||
copyPlanWebUsers();
|
||||
copyCommandUsageData();
|
||||
copyIPsAndGeolocs();
|
||||
copyNicknames();
|
||||
copySessions();
|
||||
copyUserInfo();
|
||||
copyPings();
|
||||
copyGeoInformation();
|
||||
copyNicknameData();
|
||||
copySessionsWithKillAndWorldData();
|
||||
copyPerServerUserInformation();
|
||||
copyPingData();
|
||||
}
|
||||
|
||||
private <T> void copy(Function<T, Executable> executableCreator, Query<T> dataQuery) {
|
||||
@ -64,47 +65,47 @@ public class BackupCopyTransaction extends RemoveEverythingTransaction {
|
||||
execute(executableCreator.apply(sourceDB.query(dataQuery)));
|
||||
}
|
||||
|
||||
private void copyPings() {
|
||||
db.getPingTable().insertAllPings(sourceDB.query(LargeFetchQueries.fetchAllPingData()));
|
||||
private void copyPingData() {
|
||||
copy(LargeStoreQueries::storeAllPingData, LargeFetchQueries.fetchAllPingData());
|
||||
}
|
||||
|
||||
private void copyCommandUsageData() {
|
||||
copy(LargeStoreQueries::storeAllCommandUsageData, LargeFetchQueries.fetchAllCommandUsageData());
|
||||
}
|
||||
|
||||
private void copyIPsAndGeolocs() {
|
||||
copy(LargeStoreQueries::storeAllGeoInfoData, LargeFetchQueries.fetchAllGeoInfoData());
|
||||
private void copyGeoInformation() {
|
||||
copy(LargeStoreQueries::storeAllGeoInformation, LargeFetchQueries.fetchAllGeoInformation());
|
||||
}
|
||||
|
||||
private void copyNicknames() {
|
||||
private void copyNicknameData() {
|
||||
copy(LargeStoreQueries::storeAllNicknameData, LargeFetchQueries.fetchAllNicknameData());
|
||||
}
|
||||
|
||||
private void copyWebUsers() {
|
||||
private void copyPlanWebUsers() {
|
||||
copy(LargeStoreQueries::storeAllPlanWebUsers, LargeFetchQueries.fetchAllPlanWebUsers());
|
||||
}
|
||||
|
||||
private void copyServers() {
|
||||
private void copyPlanServerInformation() {
|
||||
copy(LargeStoreQueries::storeAllPlanServerInformation, LargeFetchQueries.fetchPlanServerInformationCollection());
|
||||
}
|
||||
|
||||
private void copyTPS() {
|
||||
private void copyTPSData() {
|
||||
copy(LargeStoreQueries::storeAllTPSData, LargeFetchQueries.fetchAllTPSData());
|
||||
}
|
||||
|
||||
private void copyUserInfo() {
|
||||
private void copyPerServerUserInformation() {
|
||||
copy(LargeStoreQueries::storePerServerUserInformation, LargeFetchQueries.fetchPerServerUserInformation());
|
||||
}
|
||||
|
||||
private void copyWorlds() {
|
||||
private void copyWorldNames() {
|
||||
copy(LargeStoreQueries::storeAllWorldNames, LargeFetchQueries.fetchAllWorldNames());
|
||||
}
|
||||
|
||||
private void copyUsers() {
|
||||
private void copyCommonUserInformation() {
|
||||
copy(LargeStoreQueries::storeAllCommonUserInformation, LargeFetchQueries.fetchAllCommonUserInformation());
|
||||
}
|
||||
|
||||
private void copySessions() {
|
||||
private void copySessionsWithKillAndWorldData() {
|
||||
copy(LargeStoreQueries::storeAllSessionsWithKillAndWorldData, LargeFetchQueries.fetchAllSessionsFlatWithKillAndWorldData());
|
||||
}
|
||||
}
|
@ -68,7 +68,7 @@ public class IPAnonPatch extends Patch {
|
||||
|
||||
@Override
|
||||
protected void applyPatch() {
|
||||
Map<UUID, List<GeoInfo>> allGeoInfo = db.query(LargeFetchQueries.fetchAllGeoInfoData());
|
||||
Map<UUID, List<GeoInfo>> allGeoInfo = db.query(LargeFetchQueries.fetchAllGeoInformation());
|
||||
anonymizeIPs(allGeoInfo);
|
||||
groupHashedIPs();
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ public class LargeFetchQueries {
|
||||
*
|
||||
* @return Map: Player UUID - List of GeoInfo
|
||||
*/
|
||||
public static Query<Map<UUID, List<GeoInfo>>> fetchAllGeoInfoData() {
|
||||
public static Query<Map<UUID, List<GeoInfo>>> fetchAllGeoInformation() {
|
||||
String sql = "SELECT " +
|
||||
GeoInfoTable.IP + ", " +
|
||||
GeoInfoTable.GEOLOCATION + ", " +
|
||||
|
@ -82,7 +82,7 @@ public class LargeStoreQueries {
|
||||
* @param ofUsers Map: Player UUID - List of GeoInfo
|
||||
* @return Executable, use inside a {@link com.djrapitops.plan.db.access.transactions.Transaction}
|
||||
*/
|
||||
public static Executable storeAllGeoInfoData(Map<UUID, List<GeoInfo>> ofUsers) {
|
||||
public static Executable storeAllGeoInformation(Map<UUID, List<GeoInfo>> ofUsers) {
|
||||
if (Verify.isEmpty(ofUsers)) {
|
||||
return Executable.empty();
|
||||
}
|
||||
@ -450,4 +450,35 @@ public class LargeStoreQueries {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Executable storeAllPingData(Map<UUID, List<Ping>> ofUsers) {
|
||||
if (Verify.isEmpty(ofUsers)) {
|
||||
return Executable.empty();
|
||||
}
|
||||
|
||||
return new ExecBatchStatement(PingTable.INSERT_STATEMENT) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
for (Map.Entry<UUID, List<Ping>> entry : ofUsers.entrySet()) {
|
||||
UUID uuid = entry.getKey();
|
||||
List<Ping> pings = entry.getValue();
|
||||
for (Ping ping : pings) {
|
||||
UUID serverUUID = ping.getServerUUID();
|
||||
long date = ping.getDate();
|
||||
int minPing = ping.getMin();
|
||||
int maxPing = ping.getMax();
|
||||
double avgPing = ping.getAverage();
|
||||
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setString(2, serverUUID.toString());
|
||||
statement.setLong(3, date);
|
||||
statement.setInt(4, minPing);
|
||||
statement.setInt(5, maxPing);
|
||||
statement.setDouble(6, avgPing);
|
||||
statement.addBatch();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -170,7 +170,7 @@ public class GeoInfoTable extends Table {
|
||||
public List<String> getNetworkGeolocations() {
|
||||
List<String> geolocations = new ArrayList<>();
|
||||
|
||||
Map<UUID, List<GeoInfo>> geoInfo = db.query(LargeFetchQueries.fetchAllGeoInfoData());
|
||||
Map<UUID, List<GeoInfo>> geoInfo = db.query(LargeFetchQueries.fetchAllGeoInformation());
|
||||
for (List<GeoInfo> userGeoInfos : geoInfo.values()) {
|
||||
if (userGeoInfos.isEmpty()) {
|
||||
continue;
|
||||
|
@ -31,7 +31,6 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@ -54,18 +53,17 @@ public class PingTable extends Table {
|
||||
public static final String AVG_PING = "avg_ping";
|
||||
public static final String MIN_PING = "min_ping";
|
||||
|
||||
private final String insertStatement;
|
||||
public static final String INSERT_STATEMENT = "INSERT INTO " + TABLE_NAME + " (" +
|
||||
USER_UUID + ", " +
|
||||
SERVER_UUID + ", " +
|
||||
DATE + ", " +
|
||||
MIN_PING + ", " +
|
||||
MAX_PING + ", " +
|
||||
AVG_PING +
|
||||
") VALUES (?, ?, ?, ?, ?, ?)";
|
||||
|
||||
public PingTable(SQLDB db) {
|
||||
super(TABLE_NAME, db);
|
||||
insertStatement = "INSERT INTO " + tableName + " (" +
|
||||
USER_UUID + ", " +
|
||||
SERVER_UUID + ", " +
|
||||
DATE + ", " +
|
||||
MIN_PING + ", " +
|
||||
MAX_PING + ", " +
|
||||
AVG_PING +
|
||||
") VALUES (?, ?, ?, ?, ?, ?)";
|
||||
}
|
||||
|
||||
public static String createTableSQL(DBType dbType) {
|
||||
@ -95,7 +93,7 @@ public class PingTable extends Table {
|
||||
}
|
||||
|
||||
public void insertPing(UUID uuid, Ping ping) {
|
||||
execute(new ExecStatement(insertStatement) {
|
||||
execute(new ExecStatement(INSERT_STATEMENT) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, uuid.toString());
|
||||
@ -137,31 +135,4 @@ public class PingTable extends Table {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void insertAllPings(Map<UUID, List<Ping>> userPings) {
|
||||
executeBatch(new ExecStatement(insertStatement) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
for (Map.Entry<UUID, List<Ping>> entry : userPings.entrySet()) {
|
||||
UUID uuid = entry.getKey();
|
||||
List<Ping> pings = entry.getValue();
|
||||
for (Ping ping : pings) {
|
||||
UUID serverUUID = ping.getServerUUID();
|
||||
long date = ping.getDate();
|
||||
int minPing = ping.getMin();
|
||||
int maxPing = ping.getMax();
|
||||
double avgPing = ping.getAverage();
|
||||
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setString(2, serverUUID.toString());
|
||||
statement.setLong(3, date);
|
||||
statement.setInt(4, minPing);
|
||||
statement.setInt(5, maxPing);
|
||||
statement.setDouble(6, avgPing);
|
||||
statement.addBatch();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
|
||||
|
||||
List<UserInfo> serverUserInfo = userInfoTable.getServerUserInfo(serverUUID); // TODO Optimize and sort out
|
||||
Map<UUID, Integer> timesKicked = usersTable.getAllTimesKicked(); // TODO Optimize and sort out
|
||||
Map<UUID, List<GeoInfo>> geoInfo = db.query(LargeFetchQueries.fetchAllGeoInfoData()); // TODO Optimize
|
||||
Map<UUID, List<GeoInfo>> geoInfo = db.query(LargeFetchQueries.fetchAllGeoInformation()); // TODO Optimize
|
||||
Map<UUID, List<Ping>> allPings = db.query(LargeFetchQueries.fetchAllPingData()); // TODO Optimize
|
||||
Map<UUID, List<Nickname>> allNicknames = db.query(LargeFetchQueries.fetchAllNicknameDataByPlayerUUIDs()); // TODO Optimize
|
||||
|
||||
@ -193,7 +193,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
|
||||
List<PlayerContainer> containers = new ArrayList<>();
|
||||
|
||||
Collection<BaseUser> users = db.query(LargeFetchQueries.fetchAllCommonUserInformation());
|
||||
Map<UUID, List<GeoInfo>> geoInfo = db.query(LargeFetchQueries.fetchAllGeoInfoData());
|
||||
Map<UUID, List<GeoInfo>> geoInfo = db.query(LargeFetchQueries.fetchAllGeoInformation());
|
||||
Map<UUID, List<Ping>> allPings = db.query(LargeFetchQueries.fetchAllPingData());
|
||||
Map<UUID, List<Nickname>> allNicknames = db.query(LargeFetchQueries.fetchAllNicknameDataByPlayerUUIDs());
|
||||
|
||||
@ -433,7 +433,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
|
||||
|
||||
@Override
|
||||
public Map<UUID, List<GeoInfo>> getAllGeoInfo() {
|
||||
return db.query(LargeFetchQueries.fetchAllGeoInfoData());
|
||||
return db.query(LargeFetchQueries.fetchAllGeoInformation());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -121,7 +121,7 @@ public class SQLSaveOps extends SQLOps implements SaveOperations {
|
||||
db.executeTransaction(new Transaction() {
|
||||
@Override
|
||||
protected void performOperations() {
|
||||
execute(LargeStoreQueries.storeAllGeoInfoData(ofUsers));
|
||||
execute(LargeStoreQueries.storeAllGeoInformation(ofUsers));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user