mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-29 16:46:46 +01:00
Store skill totals rather than calculating them on the fly for faster leaderboard queries.
This commit is contained in:
parent
203d3749ee
commit
495c4a33e5
@ -20,7 +20,7 @@ import java.util.*;
|
|||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
public final class SQLDatabaseManager implements DatabaseManager {
|
public final class SQLDatabaseManager implements DatabaseManager {
|
||||||
private static final String ALL_QUERY_VERSION = "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing+alchemy";
|
private static final String ALL_QUERY_VERSION = "total";
|
||||||
private String tablePrefix = Config.getInstance().getMySQLTablePrefix();
|
private String tablePrefix = Config.getInstance().getMySQLTablePrefix();
|
||||||
|
|
||||||
private final Map<UUID, Integer> cachedUserIDs = new HashMap<UUID, Integer>();
|
private final Map<UUID, Integer> cachedUserIDs = new HashMap<UUID, Integer>();
|
||||||
@ -225,7 +225,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|||||||
+ " taming = ?, mining = ?, repair = ?, woodcutting = ?"
|
+ " taming = ?, mining = ?, repair = ?, woodcutting = ?"
|
||||||
+ ", unarmed = ?, herbalism = ?, excavation = ?"
|
+ ", unarmed = ?, herbalism = ?, excavation = ?"
|
||||||
+ ", archery = ?, swords = ?, axes = ?, acrobatics = ?"
|
+ ", archery = ?, swords = ?, axes = ?, acrobatics = ?"
|
||||||
+ ", fishing = ?, alchemy = ? WHERE user_id = ?");
|
+ ", fishing = ?, alchemy = ?, total = ? WHERE user_id = ?");
|
||||||
statement.setInt(1, profile.getSkillLevel(SkillType.TAMING));
|
statement.setInt(1, profile.getSkillLevel(SkillType.TAMING));
|
||||||
statement.setInt(2, profile.getSkillLevel(SkillType.MINING));
|
statement.setInt(2, profile.getSkillLevel(SkillType.MINING));
|
||||||
statement.setInt(3, profile.getSkillLevel(SkillType.REPAIR));
|
statement.setInt(3, profile.getSkillLevel(SkillType.REPAIR));
|
||||||
@ -239,7 +239,11 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|||||||
statement.setInt(11, profile.getSkillLevel(SkillType.ACROBATICS));
|
statement.setInt(11, profile.getSkillLevel(SkillType.ACROBATICS));
|
||||||
statement.setInt(12, profile.getSkillLevel(SkillType.FISHING));
|
statement.setInt(12, profile.getSkillLevel(SkillType.FISHING));
|
||||||
statement.setInt(13, profile.getSkillLevel(SkillType.ALCHEMY));
|
statement.setInt(13, profile.getSkillLevel(SkillType.ALCHEMY));
|
||||||
statement.setInt(14, id);
|
int total = 0;
|
||||||
|
for (SkillType skillType : SkillType.NON_CHILD_SKILLS)
|
||||||
|
total += profile.getSkillLevel(skillType);
|
||||||
|
statement.setInt(14, total);
|
||||||
|
statement.setInt(15, id);
|
||||||
success &= (statement.executeUpdate() != 0);
|
success &= (statement.executeUpdate() != 0);
|
||||||
statement.close();
|
statement.close();
|
||||||
if (!success) {
|
if (!success) {
|
||||||
@ -838,6 +842,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|||||||
+ "`acrobatics` int(10) unsigned NOT NULL DEFAULT '0',"
|
+ "`acrobatics` int(10) unsigned NOT NULL DEFAULT '0',"
|
||||||
+ "`fishing` int(10) unsigned NOT NULL DEFAULT '0',"
|
+ "`fishing` int(10) unsigned NOT NULL DEFAULT '0',"
|
||||||
+ "`alchemy` int(10) unsigned NOT NULL DEFAULT '0',"
|
+ "`alchemy` int(10) unsigned NOT NULL DEFAULT '0',"
|
||||||
|
+ "`total` int(10) unsigned NOT NULL DEFAULT '0',"
|
||||||
+ "PRIMARY KEY (`user_id`)) "
|
+ "PRIMARY KEY (`user_id`)) "
|
||||||
+ "DEFAULT CHARSET=latin1;");
|
+ "DEFAULT CHARSET=latin1;");
|
||||||
tryClose(createStatement);
|
tryClose(createStatement);
|
||||||
@ -980,6 +985,10 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|||||||
checkNameUniqueness(statement);
|
checkNameUniqueness(statement);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
case ADD_SKILL_TOTAL:
|
||||||
|
checkUpgradeSkillTotal(connection);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1317,6 +1326,43 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkUpgradeSkillTotal(final Connection connection) throws SQLException {
|
||||||
|
ResultSet resultSet = null;
|
||||||
|
Statement statement = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
connection.setAutoCommit(false);
|
||||||
|
statement = connection.createStatement();
|
||||||
|
resultSet = statement.executeQuery("SELECT * FROM `" + tablePrefix + "skills` LIMIT 1");
|
||||||
|
|
||||||
|
ResultSetMetaData rsmeta = resultSet.getMetaData();
|
||||||
|
boolean column_exists = false;
|
||||||
|
|
||||||
|
for (int i = 1; i <= rsmeta.getColumnCount(); i++) {
|
||||||
|
if (rsmeta.getColumnName(i).equalsIgnoreCase("total")) {
|
||||||
|
column_exists = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!column_exists) {
|
||||||
|
mcMMO.p.getLogger().info("Adding skill total column to skills table...");
|
||||||
|
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "skills` ADD COLUMN `total` int NOT NULL DEFAULT '0'");
|
||||||
|
statement.executeUpdate("UPDATE `" + tablePrefix + "skills` SET `total` = (taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing+alchemy)");
|
||||||
|
statement.executeUpdate("ALTER TABLE `" + tablePrefix + "skills` ADD INDEX `idx_total` (`total`) USING BTREE");
|
||||||
|
connection.commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (SQLException ex) {
|
||||||
|
printErrors(ex);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
connection.setAutoCommit(true);
|
||||||
|
tryClose(resultSet);
|
||||||
|
tryClose(statement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void checkUpgradeDropSpout(final Statement statement) {
|
private void checkUpgradeDropSpout(final Statement statement) {
|
||||||
ResultSet resultSet = null;
|
ResultSet resultSet = null;
|
||||||
|
|
||||||
|
@ -11,5 +11,6 @@ public enum UpgradeType {
|
|||||||
ADD_UUIDS,
|
ADD_UUIDS,
|
||||||
ADD_UUIDS_PARTY,
|
ADD_UUIDS_PARTY,
|
||||||
ADD_SCOREBOARD_TIPS,
|
ADD_SCOREBOARD_TIPS,
|
||||||
DROP_NAME_UNIQUENESS;
|
DROP_NAME_UNIQUENESS,
|
||||||
|
ADD_SKILL_TOTAL,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user