mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-23 16:41:22 +01:00
User Info table structure optimization
- Replaced user_id with uuid - Replaced server_id with server_uuid - Changed network page related user counts to Map<UUID, Integer> instead of Map<Integer, Integer> signature (Server UUID instead of id)
This commit is contained in:
parent
918eed1a8f
commit
1830e71157
@ -43,10 +43,7 @@ import dagger.Lazy;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
@ -108,14 +105,13 @@ public class NetworkContainer extends DataContainer {
|
||||
putSupplier(NetworkKeys.SERVERS_TAB, () -> {
|
||||
StringBuilder serverBoxes = new StringBuilder();
|
||||
Map<Integer, List<TPS>> playersOnlineData = getValue(NetworkKeys.NETWORK_PLAYER_ONLINE_DATA).orElse(new HashMap<>());
|
||||
Map<Integer, Integer> registerData = getValue(NetworkKeys.SERVER_REGISTER_DATA).orElse(new HashMap<>());
|
||||
Map<UUID, Integer> registerData = getValue(NetworkKeys.SERVER_REGISTER_DATA).orElse(new HashMap<>());
|
||||
getValue(NetworkKeys.BUKKIT_SERVERS).orElse(new ArrayList<>())
|
||||
.stream()
|
||||
.sorted((one, two) -> String.CASE_INSENSITIVE_ORDER.compare(one.getName(), two.getName()))
|
||||
.forEach(server -> {
|
||||
int serverId = server.getId();
|
||||
TPSMutator tpsMutator = new TPSMutator(playersOnlineData.getOrDefault(serverId, new ArrayList<>()));
|
||||
int registered = registerData.getOrDefault(serverId, 0);
|
||||
TPSMutator tpsMutator = new TPSMutator(playersOnlineData.getOrDefault(server.getId(), new ArrayList<>()));
|
||||
int registered = registerData.getOrDefault(server.getUuid(), 0);
|
||||
NetworkServerBox serverBox = new NetworkServerBox(server, registered, tpsMutator, graphs);
|
||||
serverBoxes.append(serverBox.toHtml());
|
||||
});
|
||||
|
@ -74,7 +74,7 @@ public class NetworkKeys {
|
||||
public static final Key<Collection<Server>> BUKKIT_SERVERS = new Key<>(new Type<Collection<Server>>() {}, "BUKKIT_SERVERS");
|
||||
public static final Key<TreeMap<Long, Map<String, Set<UUID>>>> ACTIVITY_DATA = CommonKeys.ACTIVITY_DATA;
|
||||
public static final Key<Map<Integer, List<TPS>>> NETWORK_PLAYER_ONLINE_DATA = new Key<>(new Type<Map<Integer, List<TPS>>>() {}, "NETWORK_PLAYER_ONLINE_DATA");
|
||||
public static final Key<Map<Integer, Integer>> SERVER_REGISTER_DATA = new Key<>(new Type<Map<Integer, Integer>>() {}, "SERVER_REGISTER_DATA");
|
||||
public static final Key<Map<UUID, Integer>> SERVER_REGISTER_DATA = new Key<>(new Type<Map<UUID, Integer>>() {}, "SERVER_REGISTER_DATA");
|
||||
|
||||
private NetworkKeys() {
|
||||
/* static variable class */
|
||||
|
@ -134,5 +134,5 @@ public interface FetchOperations {
|
||||
|
||||
Map<Integer, List<TPS>> getPlayersOnlineForServers(Collection<Server> servers);
|
||||
|
||||
Map<Integer, Integer> getPlayersRegisteredForServers(Collection<Server> servers);
|
||||
Map<UUID, Integer> getPlayersRegisteredForServers(Collection<Server> servers);
|
||||
}
|
||||
|
@ -207,7 +207,8 @@ public abstract class SQLDB extends Database {
|
||||
new KillsOptimizationPatch(this),
|
||||
new SessionsOptimizationPatch(this),
|
||||
new PingOptimizationPatch(this),
|
||||
new NicknamesOptimizationPatch(this)
|
||||
new NicknamesOptimizationPatch(this),
|
||||
new UserInfoOptimizationPatch(this)
|
||||
};
|
||||
|
||||
try {
|
||||
|
@ -493,7 +493,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, Integer> getPlayersRegisteredForServers(Collection<Server> servers) {
|
||||
public Map<UUID, Integer> getPlayersRegisteredForServers(Collection<Server> servers) {
|
||||
return userInfoTable.getPlayersRegisteredForServers(servers);
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ package com.djrapitops.plan.system.database.databases.sql.operation;
|
||||
import com.djrapitops.plan.system.database.databases.operation.RemoveOperations;
|
||||
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
|
||||
import com.djrapitops.plan.system.database.databases.sql.tables.Table;
|
||||
import com.djrapitops.plan.system.database.databases.sql.tables.UserIDTable;
|
||||
import com.djrapitops.plan.system.database.databases.sql.tables.UserUUIDTable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@ -38,11 +38,11 @@ public class SQLRemoveOps extends SQLOps implements RemoveOperations {
|
||||
String webUser = usersTable.getPlayerName(uuid);
|
||||
|
||||
for (Table t : db.getAllTablesInRemoveOrder()) {
|
||||
if (!(t instanceof UserIDTable)) {
|
||||
if (!(t instanceof UserUUIDTable)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
UserIDTable table = (UserIDTable) t;
|
||||
UserUUIDTable table = (UserUUIDTable) t;
|
||||
table.removeUser(uuid);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan.system.database.databases.sql.patches;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
|
||||
import com.djrapitops.plan.system.database.databases.sql.tables.UserInfoTable;
|
||||
import com.djrapitops.plan.system.database.databases.sql.tables.UserInfoTable.Col;
|
||||
|
||||
public class UserInfoOptimizationPatch extends Patch {
|
||||
|
||||
private String tempTableName;
|
||||
private String tableName;
|
||||
|
||||
public UserInfoOptimizationPatch(SQLDB db) {
|
||||
super(db);
|
||||
tableName = UserInfoTable.TABLE_NAME;
|
||||
tempTableName = "temp_user_info";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBeenApplied() {
|
||||
return hasColumn(tableName, Col.UUID.get())
|
||||
&& hasColumn(tableName, Col.SERVER_UUID.get())
|
||||
&& !hasColumn(tableName, "user_id")
|
||||
&& !hasColumn(tableName, "server_id")
|
||||
&& !hasTable(tempTableName); // If this table exists the patch has failed to finish.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
try {
|
||||
tempOldTable();
|
||||
db.getUserInfoTable().createTable();
|
||||
|
||||
db.execute("INSERT INTO " + tableName + " (" +
|
||||
Col.UUID + ", " +
|
||||
Col.SERVER_UUID + ", " +
|
||||
Col.REGISTERED + ", " +
|
||||
Col.BANNED + ", " +
|
||||
Col.OP +
|
||||
") SELECT " +
|
||||
"(SELECT plan_users.uuid FROM plan_users WHERE plan_users.id = " + tempTableName + ".user_id LIMIT 1), " +
|
||||
"(SELECT plan_servers.uuid FROM plan_servers WHERE plan_servers.id = " + tempTableName + ".server_id LIMIT 1), " +
|
||||
Col.REGISTERED + ", " +
|
||||
Col.BANNED + ", " +
|
||||
Col.OP +
|
||||
" FROM " + tempTableName
|
||||
);
|
||||
|
||||
dropTable(tempTableName);
|
||||
} catch (Exception e) {
|
||||
throw new DBOpException(UserInfoOptimizationPatch.class.getSimpleName() + " failed.", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void tempOldTable() {
|
||||
if (!hasTable(tempTableName)) {
|
||||
renameTable(tableName, tempTableName);
|
||||
}
|
||||
}
|
||||
}
|
@ -36,60 +36,64 @@ import java.util.*;
|
||||
* <p>
|
||||
* Table Name: plan_user_info
|
||||
* <p>
|
||||
* For contained columns {@see Col}
|
||||
* Patches related to this table:
|
||||
* {@link com.djrapitops.plan.system.database.databases.sql.patches.Version10Patch}
|
||||
* {@link com.djrapitops.plan.system.database.databases.sql.patches.UserInfoOptimizationPatch}
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class UserInfoTable extends UserIDTable {
|
||||
public class UserInfoTable extends UserUUIDTable {
|
||||
|
||||
public static final String TABLE_NAME = "plan_user_info";
|
||||
|
||||
private final String insertStatement;
|
||||
|
||||
private final ServerTable serverTable;
|
||||
private final UsersTable usersTable;
|
||||
|
||||
public UserInfoTable(SQLDB db) {
|
||||
super(TABLE_NAME, db);
|
||||
serverTable = db.getServerTable();
|
||||
usersTable = db.getUsersTable();
|
||||
insertStatement = "INSERT INTO " + tableName + " (" +
|
||||
Col.UUID + ", " +
|
||||
Col.REGISTERED + ", " +
|
||||
Col.SERVER_UUID + ", " +
|
||||
Col.BANNED + ", " +
|
||||
Col.OP +
|
||||
") VALUES (?, ?, ?, ?, ?)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createTable() throws DBInitException {
|
||||
createTable(TableSqlParser.createTable(tableName)
|
||||
.column(Col.USER_ID, Sql.INT).notNull()
|
||||
.primaryKeyIDColumn(supportsMySQLQueries, Col.ID)
|
||||
.column(Col.UUID, Sql.varchar(36)).notNull()
|
||||
.column(Col.SERVER_UUID, Sql.varchar(36)).notNull()
|
||||
.column(Col.REGISTERED, Sql.LONG).notNull()
|
||||
.column(Col.OP, Sql.BOOL).notNull().defaultValue(false)
|
||||
.column(Col.BANNED, Sql.BOOL).notNull().defaultValue(false)
|
||||
.column(Col.SERVER_ID, Sql.INT).notNull()
|
||||
.foreignKey(Col.USER_ID, usersTable.getTableName(), UsersTable.Col.ID)
|
||||
.foreignKey(Col.SERVER_ID, serverTable.getTableName(), ServerTable.Col.SERVER_ID)
|
||||
.primaryKey(supportsMySQLQueries, Col.ID)
|
||||
.toString());
|
||||
}
|
||||
|
||||
private final ServerTable serverTable;
|
||||
|
||||
public UserInfoTable(SQLDB db) {
|
||||
super("plan_user_info", db);
|
||||
serverTable = db.getServerTable();
|
||||
}
|
||||
|
||||
public void registerUserInfo(UUID uuid, long registered) {
|
||||
if (!usersTable.isRegistered(uuid)) {
|
||||
usersTable.registerUser(uuid, registered, "waitingForUpdate");
|
||||
}
|
||||
|
||||
String sql = "INSERT INTO " + tableName + " (" +
|
||||
Col.USER_ID + ", " +
|
||||
Col.REGISTERED + ", " +
|
||||
Col.SERVER_ID +
|
||||
") VALUES (" +
|
||||
usersTable.statementSelectID + ", " +
|
||||
"?, " +
|
||||
serverTable.statementSelectServerID + ")";
|
||||
|
||||
execute(new ExecStatement(sql) {
|
||||
execute(new ExecStatement(insertStatement) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setLong(2, registered);
|
||||
statement.setString(3, getServerUUID().toString());
|
||||
statement.setBoolean(4, false);
|
||||
statement.setBoolean(5, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isRegistered(UUID uuid, UUID serverUUID) {
|
||||
String sql = Select.from(tableName, "COUNT(" + Col.USER_ID + ") as c")
|
||||
.where(Col.USER_ID + "=" + usersTable.statementSelectID)
|
||||
.and(Col.SERVER_ID + "=" + serverTable.statementSelectServerID)
|
||||
String sql = Select.from(tableName, "COUNT(" + Col.UUID + ") as c")
|
||||
.where(Col.UUID + "=?")
|
||||
.and(Col.SERVER_UUID + "=?")
|
||||
.toString();
|
||||
|
||||
return query(new QueryStatement<Boolean>(sql) {
|
||||
@ -112,7 +116,7 @@ public class UserInfoTable extends UserIDTable {
|
||||
|
||||
public void updateOpStatus(UUID uuid, boolean op) {
|
||||
String sql = Update.values(tableName, Col.OP)
|
||||
.where(Col.USER_ID + "=" + usersTable.statementSelectID)
|
||||
.where(Col.UUID + "=?")
|
||||
.toString();
|
||||
|
||||
execute(new ExecStatement(sql) {
|
||||
@ -126,7 +130,7 @@ public class UserInfoTable extends UserIDTable {
|
||||
|
||||
public void updateBanStatus(UUID uuid, boolean banned) {
|
||||
String sql = Update.values(tableName, Col.BANNED)
|
||||
.where(Col.USER_ID + "=" + usersTable.statementSelectID)
|
||||
.where(Col.UUID + "=?")
|
||||
.toString();
|
||||
|
||||
execute(new ExecStatement(sql) {
|
||||
@ -139,20 +143,18 @@ public class UserInfoTable extends UserIDTable {
|
||||
}
|
||||
|
||||
public Map<UUID, UserInfo> getAllUserInfo(UUID uuid) {
|
||||
String usersIDColumn = usersTable + "." + UsersTable.Col.ID;
|
||||
String serverIDColumn = serverTable + "." + ServerTable.Col.SERVER_ID;
|
||||
String usersUUIDColumn = usersTable + "." + UsersTable.Col.UUID;
|
||||
String usersNameColumn = usersTable + "." + UsersTable.Col.USER_NAME + " as name";
|
||||
String serverUUIDColumn = serverTable + "." + ServerTable.Col.SERVER_UUID + " as s_uuid";
|
||||
|
||||
String sql = "SELECT " +
|
||||
tableName + "." + Col.REGISTERED + ", " +
|
||||
Col.BANNED + ", " +
|
||||
Col.OP + ", " +
|
||||
usersNameColumn + ", " +
|
||||
serverUUIDColumn +
|
||||
Col.SERVER_UUID +
|
||||
" FROM " + tableName +
|
||||
" INNER JOIN " + usersTable + " on " + usersIDColumn + "=" + Col.USER_ID +
|
||||
" INNER JOIN " + serverTable + " on " + serverIDColumn + "=" + Col.SERVER_ID +
|
||||
" WHERE " + Col.USER_ID + "=" + usersTable.statementSelectID;
|
||||
" INNER JOIN " + usersTable + " on " + usersUUIDColumn + "=" + tableName + "." + Col.UUID +
|
||||
" WHERE " + tableName + "." + Col.UUID + "=?";
|
||||
|
||||
return query(new QueryStatement<Map<UUID, UserInfo>>(sql) {
|
||||
@Override
|
||||
@ -169,7 +171,7 @@ public class UserInfoTable extends UserIDTable {
|
||||
boolean banned = set.getBoolean(Col.BANNED.get());
|
||||
String name = set.getString("name");
|
||||
|
||||
UUID serverUUID = UUID.fromString(set.getString("s_uuid"));
|
||||
UUID serverUUID = UUID.fromString(set.getString(Col.SERVER_UUID.get()));
|
||||
map.put(serverUUID, new UserInfo(uuid, name, registered, op, banned));
|
||||
}
|
||||
return map;
|
||||
@ -182,34 +184,34 @@ public class UserInfoTable extends UserIDTable {
|
||||
}
|
||||
|
||||
public List<UserInfo> getServerUserInfo(UUID serverUUID) {
|
||||
Optional<Integer> serverID = serverTable.getServerID(serverUUID);
|
||||
if (!serverID.isPresent()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
String usersUUIDColumn = usersTable + "." + UsersTable.Col.UUID;
|
||||
String usersNameColumn = usersTable + "." + UsersTable.Col.USER_NAME + " as name";
|
||||
|
||||
Map<Integer, Map.Entry<UUID, String>> uuidsAndNamesByID = usersTable.getUUIDsAndNamesByID();
|
||||
|
||||
String sql = "SELECT * FROM " + tableName +
|
||||
" WHERE " + Col.SERVER_ID + "=?";
|
||||
String sql = "SELECT " +
|
||||
tableName + "." + Col.REGISTERED + ", " +
|
||||
Col.BANNED + ", " +
|
||||
Col.OP + ", " +
|
||||
usersNameColumn + ", " +
|
||||
tableName + "." + Col.UUID +
|
||||
" FROM " + tableName +
|
||||
" INNER JOIN " + usersTable + " on " + usersUUIDColumn + "=" + tableName + "." + Col.UUID +
|
||||
" WHERE " + Col.SERVER_UUID + "=?";
|
||||
|
||||
return query(new QueryStatement<List<UserInfo>>(sql, 20000) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setInt(1, serverID.get());
|
||||
statement.setString(1, serverUUID.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserInfo> processResults(ResultSet set) throws SQLException {
|
||||
List<UserInfo> userInfo = new ArrayList<>();
|
||||
while (set.next()) {
|
||||
UUID uuid = UUID.fromString(set.getString(Col.UUID.get()));
|
||||
String name = set.getString("name");
|
||||
long registered = set.getLong(Col.REGISTERED.get());
|
||||
boolean op = set.getBoolean(Col.OP.get());
|
||||
boolean banned = set.getBoolean(Col.BANNED.get());
|
||||
int userId = set.getInt(Col.USER_ID.get());
|
||||
|
||||
Map.Entry<UUID, String> uuidNameEntry = uuidsAndNamesByID.get(userId);
|
||||
UUID uuid = uuidNameEntry.getKey();
|
||||
String name = uuidNameEntry.getValue();
|
||||
|
||||
UserInfo info = new UserInfo(uuid, name, registered, op, banned);
|
||||
if (!userInfo.contains(info)) {
|
||||
@ -231,27 +233,21 @@ public class UserInfoTable extends UserIDTable {
|
||||
}
|
||||
|
||||
public Map<UUID, List<UserInfo>> getAllUserInfo() {
|
||||
String usersIDColumn = usersTable + "." + UsersTable.Col.ID;
|
||||
String usersUUIDColumn = usersTable + "." + UsersTable.Col.UUID + " as uuid";
|
||||
String serverIDColumn = serverTable + "." + ServerTable.Col.SERVER_ID;
|
||||
String serverUUIDColumn = serverTable + "." + ServerTable.Col.SERVER_UUID + " as s_uuid";
|
||||
String sql = "SELECT " +
|
||||
tableName + "." + Col.REGISTERED + ", " +
|
||||
Col.BANNED + ", " +
|
||||
Col.OP + ", " +
|
||||
usersUUIDColumn + ", " +
|
||||
serverUUIDColumn +
|
||||
" FROM " + tableName +
|
||||
" INNER JOIN " + usersTable + " on " + usersIDColumn + "=" + Col.USER_ID +
|
||||
" INNER JOIN " + serverTable + " on " + serverIDColumn + "=" + Col.SERVER_ID;
|
||||
Col.UUID + ", " +
|
||||
Col.SERVER_UUID +
|
||||
" FROM " + tableName;
|
||||
|
||||
return query(new QueryAllStatement<Map<UUID, List<UserInfo>>>(sql, 50000) {
|
||||
@Override
|
||||
public Map<UUID, List<UserInfo>> processResults(ResultSet set) throws SQLException {
|
||||
Map<UUID, List<UserInfo>> serverMap = new HashMap<>();
|
||||
while (set.next()) {
|
||||
UUID serverUUID = UUID.fromString(set.getString("s_uuid"));
|
||||
UUID uuid = UUID.fromString(set.getString("uuid"));
|
||||
UUID serverUUID = UUID.fromString(set.getString(Col.SERVER_UUID.get()));
|
||||
UUID uuid = UUID.fromString(set.getString(Col.UUID.get()));
|
||||
|
||||
List<UserInfo> userInfos = serverMap.getOrDefault(serverUUID, new ArrayList<>());
|
||||
|
||||
@ -273,18 +269,7 @@ public class UserInfoTable extends UserIDTable {
|
||||
return;
|
||||
}
|
||||
|
||||
String sql = "INSERT INTO " + tableName + " (" +
|
||||
Col.USER_ID + ", " +
|
||||
Col.REGISTERED + ", " +
|
||||
Col.SERVER_ID + ", " +
|
||||
Col.BANNED + ", " +
|
||||
Col.OP +
|
||||
") VALUES (" +
|
||||
usersTable.statementSelectID + ", " +
|
||||
"?, " +
|
||||
serverTable.statementSelectServerID + ", ?, ?)";
|
||||
|
||||
executeBatch(new ExecStatement(sql) {
|
||||
executeBatch(new ExecStatement(insertStatement) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
// Every Server
|
||||
@ -308,7 +293,7 @@ public class UserInfoTable extends UserIDTable {
|
||||
String sql = "SELECT " +
|
||||
" COUNT(" + Col.REGISTERED + ") as c" +
|
||||
" FROM " + tableName +
|
||||
" WHERE " + Col.SERVER_ID + "=" + serverTable.statementSelectServerID;
|
||||
" WHERE " + Col.SERVER_UUID + "=?";
|
||||
|
||||
return query(new QueryAllStatement<Integer>(sql, 20000) {
|
||||
@Override
|
||||
@ -330,23 +315,23 @@ public class UserInfoTable extends UserIDTable {
|
||||
return isRegistered(player, getServerUUID());
|
||||
}
|
||||
|
||||
public Map<Integer, Integer> getPlayersRegisteredForServers(Collection<Server> servers) {
|
||||
public Map<UUID, Integer> getPlayersRegisteredForServers(Collection<Server> servers) {
|
||||
if (servers.isEmpty()) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
String sql = "SELECT " + Col.SERVER_ID + ", " +
|
||||
String sql = "SELECT " + Col.SERVER_UUID + ", " +
|
||||
"COUNT(" + Col.REGISTERED + ") AS count" +
|
||||
" FROM " + tableName +
|
||||
" GROUP BY " + Col.SERVER_ID;
|
||||
return query(new QueryAllStatement<Map<Integer, Integer>>(sql, 10000) {
|
||||
" GROUP BY " + Col.SERVER_UUID;
|
||||
return query(new QueryAllStatement<Map<UUID, Integer>>(sql, 10000) {
|
||||
@Override
|
||||
public Map<Integer, Integer> processResults(ResultSet set) throws SQLException {
|
||||
Map<Integer, Integer> map = new HashMap<>();
|
||||
public Map<UUID, Integer> processResults(ResultSet set) throws SQLException {
|
||||
Map<UUID, Integer> map = new HashMap<>();
|
||||
while (set.next()) {
|
||||
int serverID = set.getInt(Col.SERVER_ID.get());
|
||||
UUID serverUUID = UUID.fromString(Col.SERVER_UUID.get());
|
||||
int count = set.getInt("count");
|
||||
map.put(serverID, count);
|
||||
map.put(serverUUID, count);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
@ -354,9 +339,35 @@ public class UserInfoTable extends UserIDTable {
|
||||
|
||||
}
|
||||
|
||||
public Set<UUID> getSavedUUIDs(UUID serverUUID) {
|
||||
String sql = "SELECT " + Col.UUID + " FROM " + tableName + " WHERE " + Col.SERVER_UUID + "=?";
|
||||
|
||||
return query(new QueryStatement<Set<UUID>>(sql, 50000) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, serverUUID.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UUID> processResults(ResultSet set) throws SQLException {
|
||||
Set<UUID> uuids = new HashSet<>();
|
||||
while (set.next()) {
|
||||
UUID uuid = UUID.fromString(set.getString(Col.UUID.get()));
|
||||
uuids.add(uuid);
|
||||
}
|
||||
return uuids;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public enum Col implements Column {
|
||||
ID("id"),
|
||||
@Deprecated
|
||||
USER_ID(UserIDTable.Col.USER_ID.get()),
|
||||
UUID(UserUUIDTable.Col.UUID.get()),
|
||||
@Deprecated
|
||||
SERVER_ID("server_id"),
|
||||
SERVER_UUID("server_uuid"),
|
||||
REGISTERED("registered"),
|
||||
OP("opped"),
|
||||
BANNED("banned");
|
||||
@ -377,35 +388,4 @@ public class UserInfoTable extends UserIDTable {
|
||||
return column;
|
||||
}
|
||||
}
|
||||
|
||||
public Set<UUID> getSavedUUIDs(UUID serverUUID) {
|
||||
String usersIDColumn = usersTable + "." + UsersTable.Col.ID;
|
||||
String usersUUIDColumn = usersTable + "." + UsersTable.Col.UUID + " as uuid";
|
||||
String serverIDColumn = serverTable + "." + ServerTable.Col.SERVER_ID;
|
||||
String serverUUIDColumn = serverTable + "." + ServerTable.Col.SERVER_UUID + " as s_uuid";
|
||||
String sql = "SELECT " +
|
||||
usersUUIDColumn + ", " +
|
||||
serverUUIDColumn +
|
||||
" FROM " + tableName +
|
||||
" INNER JOIN " + usersTable + " on " + usersIDColumn + "=" + Col.USER_ID +
|
||||
" INNER JOIN " + serverTable + " on " + serverIDColumn + "=" + Col.SERVER_ID +
|
||||
" WHERE s_uuid=?";
|
||||
|
||||
return query(new QueryStatement<Set<UUID>>(sql, 50000) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, serverUUID.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UUID> processResults(ResultSet set) throws SQLException {
|
||||
Set<UUID> uuids = new HashSet<>();
|
||||
while (set.next()) {
|
||||
UUID uuid = UUID.fromString(set.getString("uuid"));
|
||||
uuids.add(uuid);
|
||||
}
|
||||
return uuids;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -249,7 +249,7 @@ public class UsersTable extends UserUUIDTable {
|
||||
String sql = "SELECT DISTINCT " + Col.USER_NAME + " FROM " + tableName +
|
||||
" WHERE LOWER(" + Col.USER_NAME + ") LIKE LOWER(?)" +
|
||||
" UNION SELECT DISTINCT " + Col.USER_NAME + " FROM " + tableName +
|
||||
" INNER JOIN " + nicknamesTable + " on " + Col.UUID + "=" + nicknamesTable + "." + NicknamesTable.Col.UUID +
|
||||
" INNER JOIN " + nicknamesTable + " on " + tableName + "." + Col.UUID + "=" + nicknamesTable + "." + NicknamesTable.Col.UUID +
|
||||
" WHERE LOWER(" + NicknamesTable.Col.NICKNAME + ") LIKE LOWER(?)";
|
||||
|
||||
return query(new QueryStatement<List<String>>(sql, 5000) {
|
||||
@ -423,7 +423,6 @@ public class UsersTable extends UserUUIDTable {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public DataContainer getUserInformation(UUID uuid) {
|
||||
Key<DataContainer> user_data = new Key<>(DataContainer.class, "plan_users_data");
|
||||
DataContainer returnValue = new DataContainer();
|
||||
|
@ -414,30 +414,6 @@ public abstract class CommonDBTest {
|
||||
assertEquals(22345L, (long) lastSeen.get(playerUUID));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserInfoTableRegisterUnRegistered() throws DBInitException {
|
||||
UserInfoTable userInfoTable = db.getUserInfoTable();
|
||||
assertFalse(userInfoTable.isRegistered(playerUUID));
|
||||
UsersTable usersTable = db.getUsersTable();
|
||||
assertFalse(usersTable.isRegistered(playerUUID));
|
||||
|
||||
userInfoTable.registerUserInfo(playerUUID, 123456789L);
|
||||
|
||||
commitTest();
|
||||
|
||||
assertTrue(usersTable.isRegistered(playerUUID));
|
||||
assertTrue(userInfoTable.isRegistered(playerUUID));
|
||||
|
||||
UserInfo userInfo = userInfoTable.getUserInfo(playerUUID);
|
||||
assertEquals(playerUUID, userInfo.getUuid());
|
||||
assertEquals(123456789L, (long) usersTable.getRegisterDates().get(0));
|
||||
assertEquals(123456789L, userInfo.getRegistered());
|
||||
assertEquals(1, userInfoTable.getServerUserCount(serverUUID));
|
||||
assertEquals("waitingForUpdate", userInfo.getName());
|
||||
assertFalse(userInfo.isBanned());
|
||||
assertFalse(userInfo.isOperator());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserInfoTableRegisterRegistered() throws DBInitException {
|
||||
saveUserOne();
|
||||
@ -466,6 +442,8 @@ public abstract class CommonDBTest {
|
||||
|
||||
@Test
|
||||
public void testUserInfoTableUpdateBannedOpped() throws DBInitException {
|
||||
UsersTable usersTable = db.getUsersTable();
|
||||
usersTable.registerUser(playerUUID, 223456789L, "Test_name");
|
||||
UserInfoTable userInfoTable = db.getUserInfoTable();
|
||||
userInfoTable.registerUserInfo(playerUUID, 223456789L);
|
||||
assertTrue(userInfoTable.isRegistered(playerUUID));
|
||||
@ -539,6 +517,7 @@ public abstract class CommonDBTest {
|
||||
NicknamesTable nicknamesTable = db.getNicknamesTable();
|
||||
GeoInfoTable geoInfoTable = db.getGeoInfoTable();
|
||||
|
||||
usersTable.registerUser(playerUUID, 223456789L, "Test_name");
|
||||
userInfoTable.registerUserInfo(playerUUID, 223456789L);
|
||||
saveTwoWorlds();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user