mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-09-02 10:00:23 +02:00
Refactored TPSTable#getAllTPS to a query
This commit is contained in:
parent
721e811dc5
commit
4d235dc0b6
|
@ -17,10 +17,8 @@
|
||||||
package com.djrapitops.plan.db.sql.queries.batch;
|
package com.djrapitops.plan.db.sql.queries.batch;
|
||||||
|
|
||||||
import com.djrapitops.plan.data.WebUser;
|
import com.djrapitops.plan.data.WebUser;
|
||||||
import com.djrapitops.plan.data.container.GeoInfo;
|
import com.djrapitops.plan.data.container.*;
|
||||||
import com.djrapitops.plan.data.container.Ping;
|
import com.djrapitops.plan.data.container.builders.TPSBuilder;
|
||||||
import com.djrapitops.plan.data.container.PlayerKill;
|
|
||||||
import com.djrapitops.plan.data.container.Session;
|
|
||||||
import com.djrapitops.plan.data.store.objects.Nickname;
|
import com.djrapitops.plan.data.store.objects.Nickname;
|
||||||
import com.djrapitops.plan.db.access.Query;
|
import com.djrapitops.plan.db.access.Query;
|
||||||
import com.djrapitops.plan.db.access.QueryAllStatement;
|
import com.djrapitops.plan.db.access.QueryAllStatement;
|
||||||
|
@ -376,4 +374,53 @@ public class LargeFetchQueries {
|
||||||
return sessions;
|
return sessions;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query database for TPS data.
|
||||||
|
*
|
||||||
|
* @return Map: Server UUID - List of TPS data
|
||||||
|
*/
|
||||||
|
public static Query<Map<UUID, List<TPS>>> fetchAllTPSData() {
|
||||||
|
String serverIDColumn = ServerTable.TABLE_NAME + "." + ServerTable.Col.SERVER_ID;
|
||||||
|
String serverUUIDColumn = ServerTable.TABLE_NAME + "." + ServerTable.Col.SERVER_UUID + " as s_uuid";
|
||||||
|
String sql = "SELECT " +
|
||||||
|
TPSTable.Col.DATE + ", " +
|
||||||
|
TPSTable.Col.TPS + ", " +
|
||||||
|
TPSTable.Col.PLAYERS_ONLINE + ", " +
|
||||||
|
TPSTable.Col.CPU_USAGE + ", " +
|
||||||
|
TPSTable.Col.RAM_USAGE + ", " +
|
||||||
|
TPSTable.Col.ENTITIES + ", " +
|
||||||
|
TPSTable.Col.CHUNKS + ", " +
|
||||||
|
TPSTable.Col.FREE_DISK + ", " +
|
||||||
|
serverUUIDColumn +
|
||||||
|
" FROM " + TPSTable.TABLE_NAME +
|
||||||
|
" INNER JOIN " + ServerTable.TABLE_NAME + " on " + serverIDColumn + "=" + TPSTable.Col.SERVER_ID;
|
||||||
|
|
||||||
|
return new QueryAllStatement<Map<UUID, List<TPS>>>(sql, 50000) {
|
||||||
|
@Override
|
||||||
|
public Map<UUID, List<TPS>> processResults(ResultSet set) throws SQLException {
|
||||||
|
Map<UUID, List<TPS>> serverMap = new HashMap<>();
|
||||||
|
while (set.next()) {
|
||||||
|
UUID serverUUID = UUID.fromString(set.getString("s_uuid"));
|
||||||
|
|
||||||
|
List<TPS> tpsList = serverMap.getOrDefault(serverUUID, new ArrayList<>());
|
||||||
|
|
||||||
|
TPS tps = TPSBuilder.get()
|
||||||
|
.date(set.getLong(TPSTable.Col.DATE.get()))
|
||||||
|
.tps(set.getDouble(TPSTable.Col.TPS.get()))
|
||||||
|
.playersOnline(set.getInt(TPSTable.Col.PLAYERS_ONLINE.get()))
|
||||||
|
.usedCPU(set.getDouble(TPSTable.Col.CPU_USAGE.get()))
|
||||||
|
.usedMemory(set.getLong(TPSTable.Col.RAM_USAGE.get()))
|
||||||
|
.entities(set.getInt(TPSTable.Col.ENTITIES.get()))
|
||||||
|
.chunksLoaded(set.getInt(TPSTable.Col.CHUNKS.get()))
|
||||||
|
.freeDiskSpace(set.getLong(TPSTable.Col.FREE_DISK.get()))
|
||||||
|
.toTPS();
|
||||||
|
|
||||||
|
tpsList.add(tps);
|
||||||
|
serverMap.put(serverUUID, tpsList);
|
||||||
|
}
|
||||||
|
return serverMap;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -222,50 +222,6 @@ public class TPSTable extends Table {
|
||||||
return getPeakPlayerCount(getServerUUID(), afterDate);
|
return getPeakPlayerCount(getServerUUID(), afterDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<UUID, List<TPS>> getAllTPS() {
|
|
||||||
String serverIDColumn = serverTable + "." + ServerTable.Col.SERVER_ID;
|
|
||||||
String serverUUIDColumn = serverTable + "." + ServerTable.Col.SERVER_UUID + " as s_uuid";
|
|
||||||
String sql = "SELECT " +
|
|
||||||
Col.DATE + ", " +
|
|
||||||
Col.TPS + ", " +
|
|
||||||
Col.PLAYERS_ONLINE + ", " +
|
|
||||||
Col.CPU_USAGE + ", " +
|
|
||||||
Col.RAM_USAGE + ", " +
|
|
||||||
Col.ENTITIES + ", " +
|
|
||||||
Col.CHUNKS + ", " +
|
|
||||||
Col.FREE_DISK + ", " +
|
|
||||||
serverUUIDColumn +
|
|
||||||
" FROM " + tableName +
|
|
||||||
" INNER JOIN " + serverTable + " on " + serverIDColumn + "=" + Col.SERVER_ID;
|
|
||||||
|
|
||||||
return query(new QueryAllStatement<Map<UUID, List<TPS>>>(sql, 50000) {
|
|
||||||
@Override
|
|
||||||
public Map<UUID, List<TPS>> processResults(ResultSet set) throws SQLException {
|
|
||||||
Map<UUID, List<TPS>> serverMap = new HashMap<>();
|
|
||||||
while (set.next()) {
|
|
||||||
UUID serverUUID = UUID.fromString(set.getString("s_uuid"));
|
|
||||||
|
|
||||||
List<TPS> tpsList = serverMap.getOrDefault(serverUUID, new ArrayList<>());
|
|
||||||
|
|
||||||
TPS tps = TPSBuilder.get()
|
|
||||||
.date(set.getLong(Col.DATE.get()))
|
|
||||||
.tps(set.getDouble(Col.TPS.get()))
|
|
||||||
.playersOnline(set.getInt(Col.PLAYERS_ONLINE.get()))
|
|
||||||
.usedCPU(set.getDouble(Col.CPU_USAGE.get()))
|
|
||||||
.usedMemory(set.getLong(Col.RAM_USAGE.get()))
|
|
||||||
.entities(set.getInt(Col.ENTITIES.get()))
|
|
||||||
.chunksLoaded(set.getInt(Col.CHUNKS.get()))
|
|
||||||
.freeDiskSpace(set.getLong(Col.FREE_DISK.get()))
|
|
||||||
.toTPS();
|
|
||||||
|
|
||||||
tpsList.add(tps);
|
|
||||||
serverMap.put(serverUUID, tpsList);
|
|
||||||
}
|
|
||||||
return serverMap;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<TPS> getNetworkOnlineData() {
|
public List<TPS> getNetworkOnlineData() {
|
||||||
Optional<Server> proxyInfo = db.query(OptionalFetchQueries.proxyServerInformation());
|
Optional<Server> proxyInfo = db.query(OptionalFetchQueries.proxyServerInformation());
|
||||||
if (!proxyInfo.isPresent()) {
|
if (!proxyInfo.isPresent()) {
|
||||||
|
|
|
@ -139,7 +139,7 @@ public class BatchOperationTable extends Table {
|
||||||
if (toDB.equals(this)) {
|
if (toDB.equals(this)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
toDB.db.getTpsTable().insertAllTPS(db.getTpsTable().getAllTPS());
|
toDB.db.getTpsTable().insertAllTPS(db.query(LargeFetchQueries.fetchAllTPSData()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void copyUserInfo(BatchOperationTable toDB) {
|
public void copyUserInfo(BatchOperationTable toDB) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user