mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-21 05:50:18 +08:00
Removed WorldTable#saveWorlds
This commit is contained in:
parent
35d5db638d
commit
b5ecc227f1
@ -20,6 +20,7 @@ import com.djrapitops.plan.db.SQLDB;
|
||||
import com.djrapitops.plan.db.access.ExecBatchStatement;
|
||||
import com.djrapitops.plan.db.access.QueryAllStatement;
|
||||
import com.djrapitops.plan.db.access.QueryStatement;
|
||||
import com.djrapitops.plan.db.access.queries.LargeStoreQueries;
|
||||
import com.djrapitops.plan.db.sql.tables.SessionsTable;
|
||||
import com.djrapitops.plan.db.sql.tables.WorldTable;
|
||||
import com.djrapitops.plan.db.sql.tables.WorldTimesTable;
|
||||
@ -69,17 +70,12 @@ public class WorldsServerIDPatch extends Patch {
|
||||
|
||||
List<UUID> serverUUIDs = db.getServerTable().getServerUUIDs();
|
||||
|
||||
Map<UUID, Set<String>> worldsPerServer = new HashMap<>();
|
||||
Map<UUID, Collection<String>> worldsPerServer = new HashMap<>();
|
||||
for (UUID serverUUID : serverUUIDs) {
|
||||
worldsPerServer.put(serverUUID, getWorldNamesOld(serverUUID));
|
||||
}
|
||||
|
||||
for (Map.Entry<UUID, Set<String>> entry : worldsPerServer.entrySet()) {
|
||||
UUID serverUUID = entry.getKey();
|
||||
Set<String> worlds = entry.getValue();
|
||||
|
||||
worldTable.saveWorlds(worlds, serverUUID);
|
||||
}
|
||||
execute(LargeStoreQueries.storeAllWorldNames(worldsPerServer));
|
||||
|
||||
updateWorldTimesTableWorldIDs();
|
||||
executeSwallowingExceptions("DELETE FROM " + WorldTable.TABLE_NAME + " WHERE server_id=0");
|
||||
|
@ -18,19 +18,13 @@ package com.djrapitops.plan.db.sql.tables;
|
||||
|
||||
import com.djrapitops.plan.db.DBType;
|
||||
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.patches.Version10Patch;
|
||||
import com.djrapitops.plan.db.patches.WorldsOptimizationPatch;
|
||||
import com.djrapitops.plan.db.patches.WorldsServerIDPatch;
|
||||
import com.djrapitops.plan.db.sql.parsing.CreateTableParser;
|
||||
import com.djrapitops.plan.db.sql.parsing.Sql;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Table class representing database table plan_worlds.
|
||||
@ -74,58 +68,6 @@ public class WorldTable extends Table {
|
||||
.toString();
|
||||
}
|
||||
|
||||
public List<String> getWorlds(UUID serverUUID) {
|
||||
String sql = "SELECT * FROM " + tableName +
|
||||
" WHERE " + SERVER_UUID + "=?";
|
||||
|
||||
return query(new QueryStatement<List<String>>(sql) {
|
||||
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, serverUUID.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> processResults(ResultSet set) throws SQLException {
|
||||
List<String> worldNames = new ArrayList<>();
|
||||
while (set.next()) {
|
||||
String worldName = set.getString(NAME);
|
||||
worldNames.add(worldName);
|
||||
}
|
||||
return worldNames;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to save a list of world names.
|
||||
* <p>
|
||||
* Already saved names will not be saved.
|
||||
*
|
||||
* @param worlds List of world names.
|
||||
*/
|
||||
public void saveWorlds(Collection<String> worlds, UUID serverUUID) {
|
||||
Verify.nullCheck(worlds);
|
||||
Set<String> worldsToSave = new HashSet<>(worlds);
|
||||
|
||||
List<String> saved = getWorlds(serverUUID);
|
||||
worldsToSave.removeAll(saved);
|
||||
if (Verify.isEmpty(worlds)) {
|
||||
return;
|
||||
}
|
||||
|
||||
executeBatch(new ExecStatement(INSERT_STATEMENT) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
for (String world : worldsToSave) {
|
||||
statement.setString(1, world);
|
||||
statement.setString(2, serverUUID.toString());
|
||||
statement.addBatch();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
@ -16,15 +16,14 @@
|
||||
*/
|
||||
package utilities;
|
||||
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.data.time.GMTimes;
|
||||
import com.djrapitops.plan.data.time.WorldTimes;
|
||||
import com.djrapitops.plan.db.SQLDB;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TestDatabaseCreator {
|
||||
@ -44,7 +43,6 @@ public class TestDatabaseCreator {
|
||||
private static final String[] gms = GMTimes.getGMKeyArray();
|
||||
private final SQLDB db = null; // TODO
|
||||
private final Random r;
|
||||
private Map<UUID, List<String>> worlds;
|
||||
|
||||
public TestDatabaseCreator() {
|
||||
File testDB = new File("src/test/resources/testDB.db".replace("/", File.separator));
|
||||
@ -60,70 +58,6 @@ public class TestDatabaseCreator {
|
||||
return;
|
||||
}
|
||||
|
||||
fillDatabase();
|
||||
// fillDatabase();
|
||||
}
|
||||
|
||||
private void fillDatabase() {
|
||||
addServers();
|
||||
addWorlds();
|
||||
addUsers();
|
||||
}
|
||||
|
||||
private void addWorlds() {
|
||||
worlds = new HashMap<>();
|
||||
|
||||
for (UUID serverUuid : SERVER_UUIDS) {
|
||||
for (int i = 0; i < r.nextInt(10); i++) {
|
||||
List<String> worldNames = worlds.getOrDefault(serverUuid, new ArrayList<>());
|
||||
worldNames.add(RandomData.randomString(50));
|
||||
worlds.put(serverUuid, worldNames);
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<UUID, List<String>> entry : worlds.entrySet()) {
|
||||
db.getWorldTable().saveWorlds(entry.getValue(), entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
private void addUsers() {
|
||||
for (int i = 0; i < 100000; i++) {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
long registered = Math.abs(r.nextLong());
|
||||
String name = uuid.toString().split("-", 2)[0];
|
||||
db.save().registerNewUser(uuid, registered, name);
|
||||
}
|
||||
}
|
||||
|
||||
private void addSession(UUID uuid, long date) {
|
||||
UUID serverUUID = SERVER_UUIDS.get(r.nextInt(SERVER_UUIDS.size()));
|
||||
List<String> worldNames = worlds.get(serverUUID);
|
||||
String world = worldNames.get(r.nextInt(worldNames.size()));
|
||||
String gm = gms[r.nextInt(gms.length)];
|
||||
|
||||
long end = date + (long) r.nextInt((int) TimeUnit.DAYS.toMillis(1L));
|
||||
|
||||
Session session = new Session(-1, uuid, serverUUID,
|
||||
date, end,
|
||||
r.nextInt(100), // mobs
|
||||
r.nextInt(50), // deaths
|
||||
r.nextInt((int) (end - date)) // afk
|
||||
);
|
||||
|
||||
WorldTimes worldTimes = new WorldTimes(new HashMap<>());
|
||||
|
||||
}
|
||||
|
||||
private void addServers() {
|
||||
for (UUID serverUuid : SERVER_UUIDS) {
|
||||
Server server = new Server(
|
||||
-1,
|
||||
serverUuid,
|
||||
serverUuid.toString().split("-", 2)[0],
|
||||
"address",
|
||||
100
|
||||
);
|
||||
db.getServerTable().saveCurrentServerInfo(server);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user