mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-09-02 10:00:23 +02:00
Refactored KillsTable#getAllPlayerKillsBySessionID to a query
This commit is contained in:
parent
cec8b7ac6c
commit
7e3950e5fc
|
@ -17,11 +17,10 @@
|
||||||
package com.djrapitops.plan.db.sql.queries.batch;
|
package com.djrapitops.plan.db.sql.queries.batch;
|
||||||
|
|
||||||
import com.djrapitops.plan.data.container.GeoInfo;
|
import com.djrapitops.plan.data.container.GeoInfo;
|
||||||
|
import com.djrapitops.plan.data.container.PlayerKill;
|
||||||
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;
|
||||||
import com.djrapitops.plan.db.sql.tables.CommandUseTable;
|
import com.djrapitops.plan.db.sql.tables.*;
|
||||||
import com.djrapitops.plan.db.sql.tables.GeoInfoTable;
|
|
||||||
import com.djrapitops.plan.db.sql.tables.ServerTable;
|
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
@ -73,6 +72,11 @@ public class LargeFetchQueries {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query database for all GeoInfo data.
|
||||||
|
*
|
||||||
|
* @return Map: Server UUID - List of GeoInfo
|
||||||
|
*/
|
||||||
public static Query<Map<UUID, List<GeoInfo>>> fetchAllGeoInfoData() {
|
public static Query<Map<UUID, List<GeoInfo>>> fetchAllGeoInfoData() {
|
||||||
String sql = "SELECT " +
|
String sql = "SELECT " +
|
||||||
GeoInfoTable.Col.IP + ", " +
|
GeoInfoTable.Col.IP + ", " +
|
||||||
|
@ -104,4 +108,43 @@ public class LargeFetchQueries {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query database for all Kill data.
|
||||||
|
*
|
||||||
|
* @return Map: Session ID - List of PlayerKills
|
||||||
|
*/
|
||||||
|
public static Query<Map<Integer, List<PlayerKill>>> fetchAllPlayerKillsBySessionID() {
|
||||||
|
String usersUUIDColumn = UsersTable.TABLE_NAME + "." + UsersTable.Col.UUID;
|
||||||
|
String usersNameColumn = UsersTable.TABLE_NAME + "." + UsersTable.Col.USER_NAME + " as victim_name";
|
||||||
|
String sql = "SELECT " +
|
||||||
|
KillsTable.Col.SESSION_ID + ", " +
|
||||||
|
KillsTable.Col.DATE + ", " +
|
||||||
|
KillsTable.Col.WEAPON + ", " +
|
||||||
|
KillsTable.Col.VICTIM_UUID + ", " +
|
||||||
|
usersNameColumn +
|
||||||
|
" FROM " + KillsTable.TABLE_NAME +
|
||||||
|
" INNER JOIN " + UsersTable.TABLE_NAME + " on " + usersUUIDColumn + "=" + KillsTable.Col.VICTIM_UUID;
|
||||||
|
|
||||||
|
return new QueryAllStatement<Map<Integer, List<PlayerKill>>>(sql, 50000) {
|
||||||
|
@Override
|
||||||
|
public Map<Integer, List<PlayerKill>> processResults(ResultSet set) throws SQLException {
|
||||||
|
Map<Integer, List<PlayerKill>> allPlayerKills = new HashMap<>();
|
||||||
|
while (set.next()) {
|
||||||
|
int sessionID = set.getInt(KillsTable.Col.SESSION_ID.get());
|
||||||
|
|
||||||
|
List<PlayerKill> playerKills = allPlayerKills.getOrDefault(sessionID, new ArrayList<>());
|
||||||
|
|
||||||
|
UUID victim = UUID.fromString(set.getString(KillsTable.Col.VICTIM_UUID.get()));
|
||||||
|
String victimName = set.getString("victim_name");
|
||||||
|
long date = set.getLong(KillsTable.Col.DATE.get());
|
||||||
|
String weapon = set.getString(KillsTable.Col.WEAPON.get());
|
||||||
|
playerKills.add(new PlayerKill(victim, weapon, date, victimName));
|
||||||
|
|
||||||
|
allPlayerKills.put(sessionID, playerKills);
|
||||||
|
}
|
||||||
|
return allPlayerKills;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -31,6 +31,7 @@ import com.djrapitops.plan.db.patches.Version10Patch;
|
||||||
import com.djrapitops.plan.db.sql.parsing.Column;
|
import com.djrapitops.plan.db.sql.parsing.Column;
|
||||||
import com.djrapitops.plan.db.sql.parsing.Sql;
|
import com.djrapitops.plan.db.sql.parsing.Sql;
|
||||||
import com.djrapitops.plan.db.sql.parsing.TableSqlParser;
|
import com.djrapitops.plan.db.sql.parsing.TableSqlParser;
|
||||||
|
import com.djrapitops.plan.db.sql.queries.batch.LargeFetchQueries;
|
||||||
import com.djrapitops.plugin.utilities.Verify;
|
import com.djrapitops.plugin.utilities.Verify;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
|
@ -240,42 +241,8 @@ public class KillsTable extends UserUUIDTable {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<Integer, List<PlayerKill>> getAllPlayerKillsBySessionID() {
|
|
||||||
String usersUUIDColumn = usersTable + "." + UsersTable.Col.UUID;
|
|
||||||
String usersNameColumn = usersTable + "." + UsersTable.Col.USER_NAME + " as victim_name";
|
|
||||||
String sql = "SELECT " +
|
|
||||||
Col.SESSION_ID + ", " +
|
|
||||||
Col.DATE + ", " +
|
|
||||||
Col.WEAPON + ", " +
|
|
||||||
Col.VICTIM_UUID + ", " +
|
|
||||||
usersNameColumn +
|
|
||||||
" FROM " + tableName +
|
|
||||||
" INNER JOIN " + usersTable + " on " + usersUUIDColumn + "=" + Col.VICTIM_UUID;
|
|
||||||
|
|
||||||
return query(new QueryAllStatement<Map<Integer, List<PlayerKill>>>(sql, 50000) {
|
|
||||||
@Override
|
|
||||||
public Map<Integer, List<PlayerKill>> processResults(ResultSet set) throws SQLException {
|
|
||||||
Map<Integer, List<PlayerKill>> allPlayerKills = new HashMap<>();
|
|
||||||
while (set.next()) {
|
|
||||||
int sessionID = set.getInt(Col.SESSION_ID.get());
|
|
||||||
|
|
||||||
List<PlayerKill> playerKills = allPlayerKills.getOrDefault(sessionID, new ArrayList<>());
|
|
||||||
|
|
||||||
UUID victim = UUID.fromString(set.getString(Col.VICTIM_UUID.get()));
|
|
||||||
String victimName = set.getString("victim_name");
|
|
||||||
long date = set.getLong(Col.DATE.get());
|
|
||||||
String weapon = set.getString(Col.WEAPON.get());
|
|
||||||
playerKills.add(new PlayerKill(victim, weapon, date, victimName));
|
|
||||||
|
|
||||||
allPlayerKills.put(sessionID, playerKills);
|
|
||||||
}
|
|
||||||
return allPlayerKills;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addKillsToSessions(Map<UUID, Map<UUID, List<Session>>> map) {
|
public void addKillsToSessions(Map<UUID, Map<UUID, List<Session>>> map) {
|
||||||
Map<Integer, List<PlayerKill>> playerKillsBySessionID = getAllPlayerKillsBySessionID();
|
Map<Integer, List<PlayerKill>> playerKillsBySessionID = db.query(LargeFetchQueries.fetchAllPlayerKillsBySessionID());
|
||||||
for (UUID serverUUID : map.keySet()) {
|
for (UUID serverUUID : map.keySet()) {
|
||||||
for (List<Session> sessions : map.get(serverUUID).values()) {
|
for (List<Session> sessions : map.get(serverUUID).values()) {
|
||||||
for (Session session : sessions) {
|
for (Session session : sessions) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user