From fd227350842964af568908de0001a754aa285a8e Mon Sep 17 00:00:00 2001
From: Rsl1122 <djrapitops@hotmail.com>
Date: Thu, 10 Jan 2019 14:21:33 +0200
Subject: [PATCH] Started using index creation task

---
 .../system/database/databases/sql/SQLDB.java  | 32 +++++++++++++------
 1 file changed, 22 insertions(+), 10 deletions(-)

diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLDB.java b/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLDB.java
index 7117276b6..262850467 100644
--- a/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLDB.java
+++ b/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/SQLDB.java
@@ -214,20 +214,32 @@ public abstract class SQLDB extends Database {
     private void setupDatabase() throws DBInitException {
         try {
             createTables();
-
-            Patch[] patches = patches();
-
-            try {
-                runnableFactory.create("Database Patch", new PatchTask(patches, locale, logger, errorHandler))
-                        .runTaskLaterAsynchronously(TimeAmount.toTicks(5L, TimeUnit.SECONDS));
-            } catch (Exception ignore) {
-                // Task failed to register because plugin is being disabled
-            }
-        } catch (DBOpException e) {
+            registerIndexCreationTask();
+            registerPatchTask();
+        } catch (DBOpException | IllegalArgumentException e) {
             throw new DBInitException("Failed to set-up Database", e);
         }
     }
 
+    private void registerPatchTask() {
+        Patch[] patches = patches();
+        try {
+            runnableFactory.create("Database Patch", new PatchTask(patches, locale, logger, errorHandler))
+                    .runTaskLaterAsynchronously(TimeAmount.toTicks(5L, TimeUnit.SECONDS));
+        } catch (Exception ignore) {
+            // Task failed to register because plugin is being disabled
+        }
+    }
+
+    private void registerIndexCreationTask() {
+        try {
+            runnableFactory.create("Database Index Creation", new CreateIndexTask(this))
+                    .runTaskAsynchronously();
+        } catch (Exception ignore) {
+            // Task failed to register because plugin is being disabled
+        }
+    }
+
     /**
      * Creates the tables that contain data.
      * <p>