diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/patches/IPAnonPatch.java b/Plan/common/src/main/java/com/djrapitops/plan/db/patches/IPAnonPatch.java index 568cb71c8..969487971 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/patches/IPAnonPatch.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/patches/IPAnonPatch.java @@ -22,6 +22,7 @@ import com.djrapitops.plan.data.container.GeoInfo; import com.djrapitops.plan.db.SQLDB; import com.djrapitops.plan.db.access.ExecStatement; import com.djrapitops.plan.db.access.QueryStatement; +import com.djrapitops.plan.db.sql.queries.batch.LargeFetchQueries; import com.djrapitops.plan.db.sql.tables.GeoInfoTable; import java.net.InetAddress; @@ -69,7 +70,7 @@ public class IPAnonPatch extends Patch { @Override protected void applyPatch() { - Map> allGeoInfo = db.getGeoInfoTable().getAllGeoInfo(); + Map> allGeoInfo = db.query(LargeFetchQueries.fetchAllGeoInfoData()); anonymizeIPs(allGeoInfo); groupHashedIPs(); } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/sql/queries/batch/LargeFetchQueries.java b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/queries/batch/LargeFetchQueries.java index 47e157cab..f01d99d7b 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/sql/queries/batch/LargeFetchQueries.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/queries/batch/LargeFetchQueries.java @@ -16,16 +16,16 @@ */ package com.djrapitops.plan.db.sql.queries.batch; +import com.djrapitops.plan.data.container.GeoInfo; import com.djrapitops.plan.db.access.Query; import com.djrapitops.plan.db.access.QueryAllStatement; import com.djrapitops.plan.db.sql.tables.CommandUseTable; +import com.djrapitops.plan.db.sql.tables.GeoInfoTable; import com.djrapitops.plan.db.sql.tables.ServerTable; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; +import java.util.*; /** * Static method class for queries that use large amount of memory. @@ -73,4 +73,35 @@ public class LargeFetchQueries { }; } + public static Query>> fetchAllGeoInfoData() { + String sql = "SELECT " + + GeoInfoTable.Col.IP + ", " + + GeoInfoTable.Col.GEOLOCATION + ", " + + GeoInfoTable.Col.LAST_USED + ", " + + GeoInfoTable.Col.IP_HASH + ", " + + GeoInfoTable.Col.UUID + + " FROM " + GeoInfoTable.TABLE_NAME; + + return new QueryAllStatement>>(sql, 50000) { + @Override + public Map> processResults(ResultSet set) throws SQLException { + Map> geoLocations = new HashMap<>(); + while (set.next()) { + UUID uuid = UUID.fromString(set.getString(GeoInfoTable.Col.UUID.get())); + + List userGeoInfo = geoLocations.getOrDefault(uuid, new ArrayList<>()); + + String ip = set.getString(GeoInfoTable.Col.IP.get()); + String geolocation = set.getString(GeoInfoTable.Col.GEOLOCATION.get()); + String ipHash = set.getString(GeoInfoTable.Col.IP_HASH.get()); + long lastUsed = set.getLong(GeoInfoTable.Col.LAST_USED.get()); + userGeoInfo.add(new GeoInfo(ip, geolocation, lastUsed, ipHash)); + + geoLocations.put(uuid, userGeoInfo); + } + return geoLocations; + } + }; + } + } \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/GeoInfoTable.java b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/GeoInfoTable.java index dc094ea3d..b1719778e 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/GeoInfoTable.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/GeoInfoTable.java @@ -20,13 +20,13 @@ import com.djrapitops.plan.api.exceptions.database.DBInitException; import com.djrapitops.plan.data.container.GeoInfo; import com.djrapitops.plan.db.SQLDB; import com.djrapitops.plan.db.access.ExecStatement; -import com.djrapitops.plan.db.access.QueryAllStatement; import com.djrapitops.plan.db.access.QueryStatement; import com.djrapitops.plan.db.patches.*; import com.djrapitops.plan.db.sql.parsing.Column; import com.djrapitops.plan.db.sql.parsing.Select; import com.djrapitops.plan.db.sql.parsing.Sql; import com.djrapitops.plan.db.sql.parsing.TableSqlParser; +import com.djrapitops.plan.db.sql.queries.batch.LargeFetchQueries; import com.djrapitops.plan.utilities.comparators.GeoInfoComparator; import com.djrapitops.plugin.utilities.Verify; @@ -166,41 +166,10 @@ public class GeoInfoTable extends UserUUIDTable { }); } - public Map> getAllGeoInfo() { - String sql = "SELECT " + - Col.IP + ", " + - Col.GEOLOCATION + ", " + - Col.LAST_USED + ", " + - Col.IP_HASH + ", " + - Col.UUID + - " FROM " + tableName; - - return query(new QueryAllStatement>>(sql, 50000) { - @Override - public Map> processResults(ResultSet set) throws SQLException { - Map> geoLocations = new HashMap<>(); - while (set.next()) { - UUID uuid = UUID.fromString(set.getString(Col.UUID.get())); - - List userGeoInfo = geoLocations.getOrDefault(uuid, new ArrayList<>()); - - String ip = set.getString(Col.IP.get()); - String geolocation = set.getString(Col.GEOLOCATION.get()); - String ipHash = set.getString(Col.IP_HASH.get()); - long lastUsed = set.getLong(Col.LAST_USED.get()); - userGeoInfo.add(new GeoInfo(ip, geolocation, lastUsed, ipHash)); - - geoLocations.put(uuid, userGeoInfo); - } - return geoLocations; - } - }); - } - public List getNetworkGeolocations() { List geolocations = new ArrayList<>(); - Map> geoInfo = getAllGeoInfo(); + Map> geoInfo = db.query(LargeFetchQueries.fetchAllGeoInfoData()); for (List userGeoInfos : geoInfo.values()) { if (userGeoInfos.isEmpty()) { continue; diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/move/BatchOperationTable.java b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/move/BatchOperationTable.java index 636d007e7..d57721740 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/move/BatchOperationTable.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/tables/move/BatchOperationTable.java @@ -115,7 +115,7 @@ public class BatchOperationTable extends Table { if (toDB.equals(this)) { return; } - toDB.db.getGeoInfoTable().insertAllGeoInfo(db.getGeoInfoTable().getAllGeoInfo()); + toDB.db.getGeoInfoTable().insertAllGeoInfo(db.query(LargeFetchQueries.fetchAllGeoInfoData())); } public void copyNicknames(BatchOperationTable toDB) { diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLFetchOps.java b/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLFetchOps.java index 31045efd2..ca1760b36 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLFetchOps.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLFetchOps.java @@ -27,6 +27,7 @@ import com.djrapitops.plan.data.store.objects.DateObj; import com.djrapitops.plan.data.store.objects.Nickname; import com.djrapitops.plan.data.time.WorldTimes; import com.djrapitops.plan.db.SQLDB; +import com.djrapitops.plan.db.sql.queries.batch.LargeFetchQueries; import com.djrapitops.plan.system.cache.SessionCache; import com.djrapitops.plan.system.database.databases.operation.FetchOperations; import com.djrapitops.plan.system.info.server.Server; @@ -123,7 +124,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations { List serverUserInfo = userInfoTable.getServerUserInfo(serverUUID); Map timesKicked = usersTable.getAllTimesKicked(); - Map> geoInfo = geoInfoTable.getAllGeoInfo(); + Map> geoInfo = db.query(LargeFetchQueries.fetchAllGeoInfoData()); Map> allPings = pingTable.getAllPings(); Map> allNicknames = nicknamesTable.getAllNicknamesUnmapped(); @@ -188,7 +189,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations { Map users = usersTable.getUsers(); Map timesKicked = usersTable.getAllTimesKicked(); - Map> geoInfo = geoInfoTable.getAllGeoInfo(); + Map> geoInfo = db.query(LargeFetchQueries.fetchAllGeoInfoData()); Map> allPings = pingTable.getAllPings(); Map> allNicknames = nicknamesTable.getAllNicknamesUnmapped(); @@ -428,7 +429,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations { @Override public Map> getAllGeoInfo() { - return geoInfoTable.getAllGeoInfo(); + return db.query(LargeFetchQueries.fetchAllGeoInfoData()); } @Override