mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-27 03:27:37 +01:00
Refactored NicknamesTable#getAllNicknames to a query
This commit is contained in:
parent
8f1b35d4d5
commit
cd51c9a8de
@ -18,6 +18,7 @@ package com.djrapitops.plan.db.sql.queries.batch;
|
||||
|
||||
import com.djrapitops.plan.data.container.GeoInfo;
|
||||
import com.djrapitops.plan.data.container.PlayerKill;
|
||||
import com.djrapitops.plan.data.store.objects.Nickname;
|
||||
import com.djrapitops.plan.db.access.Query;
|
||||
import com.djrapitops.plan.db.access.QueryAllStatement;
|
||||
import com.djrapitops.plan.db.sql.tables.*;
|
||||
@ -113,7 +114,7 @@ public class LargeFetchQueries {
|
||||
*
|
||||
* @return Map: Session ID - List of PlayerKills
|
||||
*/
|
||||
public static Query<Map<Integer, List<PlayerKill>>> fetchAllPlayerKillsBySessionID() {
|
||||
public static Query<Map<Integer, List<PlayerKill>>> fetchAllPlayerKillDataBySessionID() {
|
||||
String usersUUIDColumn = UsersTable.TABLE_NAME + "." + UsersTable.Col.UUID;
|
||||
String usersNameColumn = UsersTable.TABLE_NAME + "." + UsersTable.Col.USER_NAME + " as victim_name";
|
||||
String sql = "SELECT " +
|
||||
@ -147,4 +148,42 @@ public class LargeFetchQueries {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Query database for all nickname data.
|
||||
*
|
||||
* @return Multimap: Server UUID - (Player UUID - List of nicknames)
|
||||
*/
|
||||
public static Query<Map<UUID, Map<UUID, List<Nickname>>>> fetchAllNicknameData() {
|
||||
String sql = "SELECT " +
|
||||
NicknamesTable.Col.NICKNAME + ", " +
|
||||
NicknamesTable.Col.LAST_USED + ", " +
|
||||
NicknamesTable.Col.UUID + ", " +
|
||||
NicknamesTable.Col.SERVER_UUID +
|
||||
" FROM " + NicknamesTable.TABLE_NAME;
|
||||
|
||||
return new QueryAllStatement<Map<UUID, Map<UUID, List<Nickname>>>>(sql, 5000) {
|
||||
@Override
|
||||
public Map<UUID, Map<UUID, List<Nickname>>> processResults(ResultSet set) throws SQLException {
|
||||
Map<UUID, Map<UUID, List<Nickname>>> map = new HashMap<>();
|
||||
while (set.next()) {
|
||||
UUID serverUUID = UUID.fromString(set.getString(NicknamesTable.Col.SERVER_UUID.get()));
|
||||
UUID uuid = UUID.fromString(set.getString(NicknamesTable.Col.UUID.get()));
|
||||
|
||||
Map<UUID, List<Nickname>> serverMap = map.getOrDefault(serverUUID, new HashMap<>());
|
||||
List<Nickname> nicknames = serverMap.getOrDefault(uuid, new ArrayList<>());
|
||||
|
||||
nicknames.add(new Nickname(
|
||||
set.getString(NicknamesTable.Col.NICKNAME.get()),
|
||||
set.getLong(NicknamesTable.Col.LAST_USED.get()),
|
||||
serverUUID
|
||||
));
|
||||
|
||||
serverMap.put(uuid, nicknames);
|
||||
map.put(serverUUID, serverMap);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
@ -211,7 +211,7 @@ public class KillsTable extends UserUUIDTable {
|
||||
}
|
||||
|
||||
public void addKillsToSessions(Map<UUID, Map<UUID, List<Session>>> map) {
|
||||
Map<Integer, List<PlayerKill>> playerKillsBySessionID = db.query(LargeFetchQueries.fetchAllPlayerKillsBySessionID());
|
||||
Map<Integer, List<PlayerKill>> playerKillsBySessionID = db.query(LargeFetchQueries.fetchAllPlayerKillDataBySessionID());
|
||||
for (UUID serverUUID : map.keySet()) {
|
||||
for (List<Session> sessions : map.get(serverUUID).values()) {
|
||||
for (Session session : sessions) {
|
||||
|
@ -158,9 +158,7 @@ public class NicknamesTable extends UserUUIDTable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get nicknames of all users but doesn't map them by Server
|
||||
*
|
||||
* See {@link NicknamesTable#getAllNicknames}
|
||||
* Get nicknames of all users but doesn't map them by Server.
|
||||
*
|
||||
* @return a {@code Map<UUID, List<Nickname>} with all nicknames of all users
|
||||
*
|
||||
|
@ -122,7 +122,7 @@ public class BatchOperationTable extends Table {
|
||||
if (toDB.equals(this)) {
|
||||
return;
|
||||
}
|
||||
toDB.db.getNicknamesTable().insertNicknames(db.getNicknamesTable().getAllNicknames());
|
||||
toDB.db.getNicknamesTable().insertNicknames(db.query(LargeFetchQueries.fetchAllNicknameData()));
|
||||
}
|
||||
|
||||
public void copyWebUsers(BatchOperationTable toDB) {
|
||||
|
Loading…
Reference in New Issue
Block a user