Change table names and add date indexes based on Jon's request

This commit is contained in:
AlexTheCoder 2017-05-11 20:49:38 -04:00
parent 4a05149743
commit a76572f6d7

View File

@ -20,25 +20,25 @@ public class LeaderboardRepository extends RepositoryBase
{ {
private static final int SEASON = 1; private static final int SEASON = 1;
private static final String CREATE_TOTAL = "CREATE TABLE accountSeasonStatsTotal (accountId INT NOT NULL, statId INT NOT NULL, season SMALLINT NOT NULL, value BIGINT NOT NULL, PRIMARY KEY (accountId, statId, season), INDEX valueIndex (value DESC), FOREIGN KEY (accountId) REFERENCES accounts(id), FOREIGN KEY (statId) REFERENCES stats(id));"; private static final String CREATE_TOTAL = "CREATE TABLE accountStatsSeasonalTotal (accountId INT NOT NULL, statId INT NOT NULL, season SMALLINT NOT NULL, value BIGINT NOT NULL, PRIMARY KEY (accountId, statId, season), INDEX valueIndex (value DESC), FOREIGN KEY (accountId) REFERENCES accounts(id), FOREIGN KEY (statId) REFERENCES stats(id));";
private static final String CREATE_YEARLY = "CREATE TABLE accountSeasonStatsYearly (accountId INT NOT NULL, statId INT NOT NULL, date DATE NOT NULL, value BIGINT NOT NULL, PRIMARY KEY (accountId, statId), INDEX valueIndex (value DESC), FOREIGN KEY (accountId) REFERENCES accounts(id), FOREIGN KEY (statId) REFERENCES stats(id));"; private static final String CREATE_YEARLY = "CREATE TABLE accountStatsYearly (accountId INT NOT NULL, statId INT NOT NULL, date DATE NOT NULL, value BIGINT NOT NULL, PRIMARY KEY (accountId, statId), INDEX valueIndex (value DESC), INDEX dateIndex (date), FOREIGN KEY (accountId) REFERENCES accounts(id), FOREIGN KEY (statId) REFERENCES stats(id));";
private static final String CREATE_MONTHLY = "CREATE TABLE accountSeasonStatsMonthly (accountId INT NOT NULL, statId INT NOT NULL, date DATE NOT NULL, value BIGINT NOT NULL, PRIMARY KEY (accountId, statId), INDEX valueIndex (value DESC), FOREIGN KEY (accountId) REFERENCES accounts(id), FOREIGN KEY (statId) REFERENCES stats(id));"; private static final String CREATE_MONTHLY = "CREATE TABLE accountStatsMonthly (accountId INT NOT NULL, statId INT NOT NULL, date DATE NOT NULL, value BIGINT NOT NULL, PRIMARY KEY (accountId, statId), INDEX valueIndex (value DESC), INDEX dateIndex (date), FOREIGN KEY (accountId) REFERENCES accounts(id), FOREIGN KEY (statId) REFERENCES stats(id));";
private static final String CREATE_WEEKLY = "CREATE TABLE accountSeasonStatsWeekly (accountId INT NOT NULL, statId INT NOT NULL, date DATE NOT NULL, value BIGINT NOT NULL, PRIMARY KEY (accountId, statId), INDEX valueIndex (value DESC), FOREIGN KEY (accountId) REFERENCES accounts(id), FOREIGN KEY (statId) REFERENCES stats(id));"; private static final String CREATE_WEEKLY = "CREATE TABLE accountStatsWeekly (accountId INT NOT NULL, statId INT NOT NULL, date DATE NOT NULL, value BIGINT NOT NULL, PRIMARY KEY (accountId, statId), INDEX valueIndex (value DESC), INDEX dateIndex (date), FOREIGN KEY (accountId) REFERENCES accounts(id), FOREIGN KEY (statId) REFERENCES stats(id));";
private static final String CREATE_DAILY = "CREATE TABLE accountSeasonStatsDaily (accountId INT NOT NULL, statId INT NOT NULL, date DATE NOT NULL, value BIGINT NOT NULL, PRIMARY KEY (accountId, statId), INDEX valueIndex (value DESC), FOREIGN KEY (accountId) REFERENCES accounts(id), FOREIGN KEY (statId) REFERENCES stats(id));"; private static final String CREATE_DAILY = "CREATE TABLE accountStatsDaily (accountId INT NOT NULL, statId INT NOT NULL, date DATE NOT NULL, value BIGINT NOT NULL, PRIMARY KEY (accountId, statId), INDEX valueIndex (value DESC), INDEX dateIndex (date), FOREIGN KEY (accountId) REFERENCES accounts(id), FOREIGN KEY (statId) REFERENCES stats(id));";
private static final String INSERT_STAT = "INSERT INTO accountSeasonStatsTotal (accountId, statId, season, value) VALUES (?, ?, " + SEASON + ", ?);"; private static final String INSERT_STAT = "INSERT INTO accountStatsSeasonalTotal (accountId, statId, season, value) VALUES (?, ?, " + SEASON + ", ?);";
private static final String INSERT_STAT_ALL = "INSERT INTO accountSeasonStatsTotal (accountId, statId, season, value) VALUES (?, ?, 0, ?);"; private static final String INSERT_STAT_ALL = "INSERT INTO accountStatsSeasonalTotal (accountId, statId, season, value) VALUES (?, ?, 0, ?);";
private static final String UPDATE_STAT = "UPDATE accountSeasonStatsTotal SET value=value + ? WHERE accountId=? AND statId=? AND season=" + SEASON + ";"; private static final String UPDATE_STAT = "UPDATE accountStatsSeasonalTotal SET value=value + ? WHERE accountId=? AND statId=? AND season=" + SEASON + ";";
private static final String UPDATE_STAT_ALL = "UPDATE accountSeasonStatsTotal SET value=value + ? WHERE accountId=? AND statId=? AND season=0;"; private static final String UPDATE_STAT_ALL = "UPDATE accountStatsSeasonalTotal SET value=value + ? WHERE accountId=? AND statId=? AND season=0;";
private static final String FETCH_STAT_ALL = "SELECT a.name, sl.value FROM accountSeasonStatsTotal AS sl INNER JOIN accounts AS a ON a.id=sl.accountId WHERE sl.statId=%STAT% AND season=0 ORDER BY sl.value DESC LIMIT %START%,%LIMIT%;"; private static final String FETCH_STAT_ALL = "SELECT a.name, sl.value FROM accountStatsSeasonalTotal AS sl INNER JOIN accounts AS a ON a.id=sl.accountId WHERE sl.statId=%STAT% AND season=0 ORDER BY sl.value DESC LIMIT %START%,%LIMIT%;";
private static final String FETCH_STAT_YEARLY = "SELECT a.name, sl.value FROM accountSeasonStatsYearly AS sl INNER JOIN accounts AS a ON a.id=sl.accountId WHERE YEAR(sl.date) = YEAR(CURDATE()) AND sl.statId=%STAT% ORDER BY sl.value DESC LIMIT %START%,%LIMIT%;"; private static final String FETCH_STAT_YEARLY = "SELECT a.name, sl.value FROM accountStatsYearly AS sl INNER JOIN accounts AS a ON a.id=sl.accountId WHERE YEAR(sl.date) = YEAR(CURDATE()) AND sl.statId=%STAT% ORDER BY sl.value DESC LIMIT %START%,%LIMIT%;";
private static final String FETCH_STAT_MONTHLY = "SELECT a.name, sl.value FROM accountSeasonStatsMonthly AS sl INNER JOIN accounts AS a ON a.id=sl.accountId WHERE MONTH(sl.date) = MONTH(CURDATE()) AND YEAR(sl.date) = YEAR(CURDATE()) AND sl.statId=%STAT% ORDER BY sl.value DESC LIMIT %START%,%LIMIT%;"; private static final String FETCH_STAT_MONTHLY = "SELECT a.name, sl.value FROM accountStatsMonthly AS sl INNER JOIN accounts AS a ON a.id=sl.accountId WHERE MONTH(sl.date) = MONTH(CURDATE()) AND YEAR(sl.date) = YEAR(CURDATE()) AND sl.statId=%STAT% ORDER BY sl.value DESC LIMIT %START%,%LIMIT%;";
private static final String FETCH_STAT_WEEKLY = "SELECT a.name, sl.value FROM accountSeasonStatsWeekly AS sl INNER JOIN accounts AS a ON a.id=sl.accountId WHERE YEARWEEK(sl.date, 1) = YEARWEEK(CURDATE(), 1) AND sl.statId=%STAT% ORDER BY sl.value DESC LIMIT %START%,%LIMIT%;"; private static final String FETCH_STAT_WEEKLY = "SELECT a.name, sl.value FROM accountStatsWeekly AS sl INNER JOIN accounts AS a ON a.id=sl.accountId WHERE YEARWEEK(sl.date, 1) = YEARWEEK(CURDATE(), 1) AND sl.statId=%STAT% ORDER BY sl.value DESC LIMIT %START%,%LIMIT%;";
private static final String FETCH_STAT_DAILY = "SELECT a.name, sl.value FROM accountSeasonStatsDaily AS sl INNER JOIN accounts AS a ON a.id=sl.accountId WHERE sl.date = CURDATE() AND sl.statId=%STAT% ORDER BY sl.value DESC LIMIT %START%,%LIMIT%;"; private static final String FETCH_STAT_DAILY = "SELECT a.name, sl.value FROM accountStatsDaily AS sl INNER JOIN accounts AS a ON a.id=sl.accountId WHERE sl.date = CURDATE() AND sl.statId=%STAT% ORDER BY sl.value DESC LIMIT %START%,%LIMIT%;";
private static final String FETCH_STAT_ALL_SEASON = "SELECT a.name, sl.value FROM accountSeasonStatsTotal AS sl INNER JOIN accounts AS a ON a.id=sl.accountId WHERE sl.statId=%STAT% AND season=" + SEASON + " ORDER BY sl.value DESC LIMIT %START%,%LIMIT%;"; private static final String FETCH_STAT_ALL_SEASON = "SELECT a.name, sl.value FROM accountStatsSeasonalTotal AS sl INNER JOIN accounts AS a ON a.id=sl.accountId WHERE sl.statId=%STAT% AND season=" + SEASON + " ORDER BY sl.value DESC LIMIT %START%,%LIMIT%;";
public LeaderboardRepository(JavaPlugin plugin) public LeaderboardRepository(JavaPlugin plugin)
{ {