Use existing connection for loading new year + family
Move async tasks earlier for lower chance of having to wait
This commit is contained in:
@@ -182,8 +182,7 @@ public class MapleFamily {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void loadAllFamilies() {
|
public static void loadAllFamilies(Connection con) {
|
||||||
try(Connection con = DatabaseConnection.getConnection()) {
|
|
||||||
List<Pair<Pair<Integer, Integer>, MapleFamilyEntry>> unmatchedJuniors = new ArrayList<>(200); // <<world, seniorid> familyEntry>
|
List<Pair<Pair<Integer, Integer>, MapleFamilyEntry>> unmatchedJuniors = new ArrayList<>(200); // <<world, seniorid> familyEntry>
|
||||||
try (PreparedStatement psEntries = con.prepareStatement("SELECT * FROM family_character")) {
|
try (PreparedStatement psEntries = con.prepareStatement("SELECT * FROM family_character")) {
|
||||||
ResultSet rsEntries = psEntries.executeQuery();
|
ResultSet rsEntries = psEntries.executeQuery();
|
||||||
@@ -236,7 +235,9 @@ public class MapleFamily {
|
|||||||
if (senior != null) {
|
if (senior != null) {
|
||||||
familyEntry.setSenior(family.getEntryByID(seniorid), false);
|
familyEntry.setSenior(family.getEntryByID(seniorid), false);
|
||||||
} else {
|
} else {
|
||||||
if(seniorid > 0) unmatchedJuniors.add(new Pair<>(new Pair<>(world, seniorid), familyEntry));
|
if (seniorid > 0) {
|
||||||
|
unmatchedJuniors.add(new Pair<>(new Pair<>(world, seniorid), familyEntry));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
familyEntry.setReputation(reputation);
|
familyEntry.setReputation(reputation);
|
||||||
familyEntry.setTodaysRep(todaysRep);
|
familyEntry.setTodaysRep(todaysRep);
|
||||||
@@ -267,10 +268,7 @@ public class MapleFamily {
|
|||||||
FilePrinter.printError(FilePrinter.FAMILY_ERROR, "Missing senior for character " + junior.getName() + " in world " + world);
|
FilePrinter.printError(FilePrinter.FAMILY_ERROR, "Missing senior for character " + junior.getName() + " in world " + world);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(SQLException e) {
|
|
||||||
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not get DB connection.");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
for (World world : Server.getInstance().getWorlds()) {
|
for (World world : Server.getInstance().getWorlds()) {
|
||||||
for (MapleFamily family : world.getFamilies()) {
|
for (MapleFamily family : world.getFamilies()) {
|
||||||
family.getLeader().doFullCount();
|
family.getLeader().doFullCount();
|
||||||
|
|||||||
@@ -340,8 +340,7 @@ public class NewYearCardRecord {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void startPendingNewYearCardRequests() {
|
public static void startPendingNewYearCardRequests(Connection con) throws SQLException {
|
||||||
try (Connection con = DatabaseConnection.getConnection()) {
|
|
||||||
try (PreparedStatement ps = con.prepareStatement("SELECT * FROM newyear WHERE timereceived = 0 AND senderdiscard = 0")) {
|
try (PreparedStatement ps = con.prepareStatement("SELECT * FROM newyear WHERE timereceived = 0 AND senderdiscard = 0")) {
|
||||||
try (ResultSet rs = ps.executeQuery()) {
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
@@ -353,8 +352,5 @@ public class NewYearCardRecord {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(SQLException sqle) {
|
|
||||||
sqle.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -704,7 +704,7 @@ public class Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void installWorldPlayerRanking(int worldid) {
|
private void installWorldPlayerRanking(int worldid) {
|
||||||
List<Pair<Integer, List<Pair<String, Integer>>>> ranking = updatePlayerRankingFromDB(worldid);
|
List<Pair<Integer, List<Pair<String, Integer>>>> ranking = loadPlayerRankingFromDB(worldid);
|
||||||
if (!ranking.isEmpty()) {
|
if (!ranking.isEmpty()) {
|
||||||
wldWLock.lock();
|
wldWLock.lock();
|
||||||
try {
|
try {
|
||||||
@@ -736,7 +736,7 @@ public class Server {
|
|||||||
wldWLock.unlock();
|
wldWLock.unlock();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
List<Pair<Integer, List<Pair<String, Integer>>>> ranking = updatePlayerRankingFromDB(-1 * (this.getWorldsSize() - 2)); // update ranking list
|
List<Pair<Integer, List<Pair<String, Integer>>>> ranking = loadPlayerRankingFromDB(-1 * (this.getWorldsSize() - 2)); // update ranking list
|
||||||
|
|
||||||
wldWLock.lock();
|
wldWLock.lock();
|
||||||
try {
|
try {
|
||||||
@@ -748,8 +748,11 @@ public class Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void updateWorldPlayerRanking() {
|
public void updateWorldPlayerRanking() {
|
||||||
List<Pair<Integer, List<Pair<String, Integer>>>> rankUpdates = updatePlayerRankingFromDB(-1 * (this.getWorldsSize() - 1));
|
List<Pair<Integer, List<Pair<String, Integer>>>> rankUpdates = loadPlayerRankingFromDB(-1 * (this.getWorldsSize() - 1));
|
||||||
if (!rankUpdates.isEmpty()) {
|
if (rankUpdates.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
wldWLock.lock();
|
wldWLock.lock();
|
||||||
try {
|
try {
|
||||||
if (!YamlConfig.config.server.USE_WHOLE_SERVER_RANKING) {
|
if (!YamlConfig.config.server.USE_WHOLE_SERVER_RANKING) {
|
||||||
@@ -766,22 +769,26 @@ public class Server {
|
|||||||
} finally {
|
} finally {
|
||||||
wldWLock.unlock();
|
wldWLock.unlock();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initWorldPlayerRanking() {
|
private void initWorldPlayerRanking() {
|
||||||
if (YamlConfig.config.server.USE_WHOLE_SERVER_RANKING) {
|
if (YamlConfig.config.server.USE_WHOLE_SERVER_RANKING) {
|
||||||
|
wldWLock.lock();
|
||||||
|
try {
|
||||||
playerRanking.add(new ArrayList<>(0));
|
playerRanking.add(new ArrayList<>(0));
|
||||||
|
} finally {
|
||||||
|
wldWLock.unlock();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
updateWorldPlayerRanking();
|
updateWorldPlayerRanking();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<Pair<Integer, List<Pair<String, Integer>>>> updatePlayerRankingFromDB(int worldid) {
|
private static List<Pair<Integer, List<Pair<String, Integer>>>> loadPlayerRankingFromDB(int worldid) {
|
||||||
List<Pair<Integer, List<Pair<String, Integer>>>> rankSystem = new ArrayList<>();
|
List<Pair<Integer, List<Pair<String, Integer>>>> rankSystem = new ArrayList<>();
|
||||||
List<Pair<String, Integer>> rankUpdate = new ArrayList<>(0);
|
|
||||||
|
|
||||||
try (Connection con = DatabaseConnection.getConnection()) {
|
try (Connection con = DatabaseConnection.getConnection()) {
|
||||||
|
|
||||||
String worldQuery;
|
String worldQuery;
|
||||||
if (!YamlConfig.config.server.USE_WHOLE_SERVER_RANKING) {
|
if (!YamlConfig.config.server.USE_WHOLE_SERVER_RANKING) {
|
||||||
if (worldid >= 0) {
|
if (worldid >= 0) {
|
||||||
@@ -793,6 +800,7 @@ public class Server {
|
|||||||
worldQuery = (" AND `characters`.`world` >= 0 AND `characters`.`world` <= " + Math.abs(worldid));
|
worldQuery = (" AND `characters`.`world` >= 0 AND `characters`.`world` <= " + Math.abs(worldid));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<Pair<String, Integer>> rankUpdate = new ArrayList<>(0);
|
||||||
try (PreparedStatement ps = con.prepareStatement("SELECT `characters`.`name`, `characters`.`level`, `characters`.`world` FROM `characters` LEFT JOIN accounts ON accounts.id = characters.accountid WHERE `characters`.`gm` < 2 AND `accounts`.`banned` = '0'" + worldQuery + " ORDER BY " + (!YamlConfig.config.server.USE_WHOLE_SERVER_RANKING ? "world, " : "") + "level DESC, exp DESC, lastExpGainTime ASC LIMIT 50");
|
try (PreparedStatement ps = con.prepareStatement("SELECT `characters`.`name`, `characters`.`level`, `characters`.`world` FROM `characters` LEFT JOIN accounts ON accounts.id = characters.accountid WHERE `characters`.`gm` < 2 AND `accounts`.`banned` = '0'" + worldQuery + " ORDER BY " + (!YamlConfig.config.server.USE_WHOLE_SERVER_RANKING ? "world, " : "") + "level DESC, exp DESC, lastExpGainTime ASC LIMIT 50");
|
||||||
ResultSet rs = ps.executeQuery()) {
|
ResultSet rs = ps.executeQuery()) {
|
||||||
|
|
||||||
@@ -836,22 +844,6 @@ public class Server {
|
|||||||
throw new IllegalStateException("Failed to initiate a connection to the database");
|
throw new IllegalStateException("Failed to initiate a connection to the database");
|
||||||
}
|
}
|
||||||
|
|
||||||
TimeZone.setDefault(TimeZone.getTimeZone(YamlConfig.config.server.TIMEZONE));
|
|
||||||
|
|
||||||
try (Connection con = DatabaseConnection.getConnection()) {
|
|
||||||
setAllLoggedOut(con);
|
|
||||||
setAllMerchantsInactive(con);
|
|
||||||
cleanNxcodeCoupons(con);
|
|
||||||
loadCouponRates(con);
|
|
||||||
updateActiveCoupons(con);
|
|
||||||
MapleCashidGenerator.loadExistentCashIdsFromDb(con);
|
|
||||||
applyAllNameChanges(con); // -- name changes can be missed by INSTANT_NAME_CHANGE --
|
|
||||||
applyAllWorldTransfers(con);
|
|
||||||
} catch (SQLException sqle) {
|
|
||||||
log.error("Failed to run all startup-bound database tasks", sqle);
|
|
||||||
throw new IllegalStateException(sqle);
|
|
||||||
}
|
|
||||||
|
|
||||||
final ExecutorService initExecutor = Executors.newFixedThreadPool(10);
|
final ExecutorService initExecutor = Executors.newFixedThreadPool(10);
|
||||||
// Run slow operations asynchronously to make startup faster
|
// Run slow operations asynchronously to make startup faster
|
||||||
final List<Future<?>> futures = new ArrayList<>();
|
final List<Future<?>> futures = new ArrayList<>();
|
||||||
@@ -861,11 +853,30 @@ public class Server {
|
|||||||
futures.add(initExecutor.submit(() -> MapleSkillbookInformationProvider.loadAllSkillbookInformation()));
|
futures.add(initExecutor.submit(() -> MapleSkillbookInformationProvider.loadAllSkillbookInformation()));
|
||||||
futures.add(initExecutor.submit(() -> MaplePlayerNPCFactory.loadFactoryMetadata()));
|
futures.add(initExecutor.submit(() -> MaplePlayerNPCFactory.loadFactoryMetadata()));
|
||||||
|
|
||||||
|
TimeZone.setDefault(TimeZone.getTimeZone(YamlConfig.config.server.TIMEZONE));
|
||||||
|
|
||||||
|
try (Connection con = DatabaseConnection.getConnection()) {
|
||||||
|
setAllLoggedOut(con);
|
||||||
|
setAllMerchantsInactive(con);
|
||||||
|
cleanNxcodeCoupons(con);
|
||||||
|
loadCouponRates(con);
|
||||||
|
updateActiveCoupons(con);
|
||||||
|
NewYearCardRecord.startPendingNewYearCardRequests(con);
|
||||||
|
MapleCashidGenerator.loadExistentCashIdsFromDb(con);
|
||||||
|
applyAllNameChanges(con); // -- name changes can be missed by INSTANT_NAME_CHANGE --
|
||||||
|
applyAllWorldTransfers(con);
|
||||||
|
|
||||||
|
if (YamlConfig.config.server.USE_FAMILY_SYSTEM) {
|
||||||
|
MapleFamily.loadAllFamilies(con);
|
||||||
|
}
|
||||||
|
} catch (SQLException sqle) {
|
||||||
|
log.error("Failed to run all startup-bound database tasks", sqle);
|
||||||
|
throw new IllegalStateException(sqle);
|
||||||
|
}
|
||||||
|
|
||||||
ThreadManager.getInstance().start();
|
ThreadManager.getInstance().start();
|
||||||
initializeTimelyTasks(); // aggregated method for timely tasks thanks to lxconan
|
initializeTimelyTasks(); // aggregated method for timely tasks thanks to lxconan
|
||||||
|
|
||||||
NewYearCardRecord.startPendingNewYearCardRequests();
|
|
||||||
|
|
||||||
if (YamlConfig.config.server.USE_THREAD_TRACKER) {
|
if (YamlConfig.config.server.USE_THREAD_TRACKER) {
|
||||||
ThreadTracker.getInstance().registerThreadTrackerTask();
|
ThreadTracker.getInstance().registerThreadTrackerTask();
|
||||||
}
|
}
|
||||||
@@ -885,13 +896,6 @@ public class Server {
|
|||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (YamlConfig.config.server.USE_FAMILY_SYSTEM) {
|
|
||||||
long timeToTake = System.currentTimeMillis();
|
|
||||||
MapleFamily.loadAllFamilies();
|
|
||||||
final double familyLoadTime = (System.currentTimeMillis() - timeToTake) / 1000.0;
|
|
||||||
log.info("Families loaded in {} seconds", familyLoadTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait on all async tasks to complete
|
// Wait on all async tasks to complete
|
||||||
for (Future<?> future : futures) {
|
for (Future<?> future : futures) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user