Skip to content

Commit

Permalink
Fix issue where Plan holds server enable if database is slow
Browse files Browse the repository at this point in the history
Affects issues:
- Fixed #2356
  • Loading branch information
AuroraLS3 committed May 26, 2022
1 parent c153768 commit 0538cea
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.djrapitops.plan.delivery.domain.auth.User;
import com.djrapitops.plan.identification.Server;
import com.djrapitops.plan.identification.ServerUUID;
import com.djrapitops.plan.processing.Processing;
import com.djrapitops.plan.storage.database.DBSystem;
import com.djrapitops.plan.storage.database.queries.objects.ServerQueries;
import com.djrapitops.plan.storage.database.queries.objects.UserIdentifierQueries;
Expand All @@ -39,6 +40,7 @@
@Singleton
public class TabCompleteCache implements SubSystem {

private final Processing processing;
private final PlanFiles files;
private final DBSystem dbSystem;

Expand All @@ -49,9 +51,11 @@ public class TabCompleteCache implements SubSystem {

@Inject
public TabCompleteCache(
Processing processing,
PlanFiles files,
DBSystem dbSystem
) {
this.processing = processing;
this.files = files;
this.dbSystem = dbSystem;
playerIdentifiers = new ArrayList<>();
Expand All @@ -62,15 +66,17 @@ public TabCompleteCache(

@Override
public void enable() {
refreshPlayerIdentifiers();
refreshServerIdentifiers();
refreshUserIdentifiers();
refreshBackupFileNames();

Collections.sort(playerIdentifiers);
Collections.sort(serverIdentifiers);
Collections.sort(userIdentifiers);
Collections.sort(backupFileNames);
processing.submitNonCritical(() -> {
refreshPlayerIdentifiers();
refreshServerIdentifiers();
refreshUserIdentifiers();
refreshBackupFileNames();

Collections.sort(playerIdentifiers);
Collections.sort(serverIdentifiers);
Collections.sort(userIdentifiers);
Collections.sort(backupFileNames);
});
}

private void refreshServerIdentifiers() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ protected void loadServerInfo() {
logger.info(locale.getString(PluginLang.LOADING_SERVER_INFO));
Optional<Server> loaded = fromFile.load(null);
server = loaded.orElseGet(this::registerNew);
logger.info(locale.getString(PluginLang.LOADED_SERVER_INFO, server.getUuid().toString()));
processing.submitNonCritical(this::updateStorage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public enum PluginLang implements Lang {
DB_NOTIFY_SQLITE_WAL("plugin.generic.dbNotifySQLiteWAL", "Database Notify - SQLite No WAL", "SQLite WAL mode not supported on this server version, using default. This may or may not affect performance."),
DB_MYSQL_LAUNCH_OPTIONS_FAIL("plugin.generic.dbFaultyLaunchOptions", "Database MySQL - Launch Options Error", "Launch Options were faulty, using default (${0})"),
LOADING_SERVER_INFO("plugin.generic.loadingServerInfo", "ServerInfo - Loading", "Loading server identifying information"),
LOADED_SERVER_INFO("plugin.generic.loadedServerInfo", "ServerInfo - Loaded", "Server identifier loaded: ${0}"),
DB_SCHEMA_PATCH("plugin.generic.dbSchemaPatch", "Database Notify - Patch", "Database: Making sure schema is up to date.."),
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,13 @@ Patch[] patches() {
* Updates to latest schema.
*/
private void setupDatabase() {
executeTransaction(new OperationCriticalTransaction() {
@Override
protected void performOperations() {
logger.info(locale.getString(PluginLang.DB_SCHEMA_PATCH));
}
});
executeTransaction(new CreateTablesTransaction());
logger.info(locale.getString(PluginLang.DB_SCHEMA_PATCH));
for (Patch patch : patches()) {
executeTransaction(patch);
}
Expand Down

0 comments on commit 0538cea

Please sign in to comment.