From fbb1bb72debe034d505ac4b0a0d6186f8e938440 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Sat, 26 Jan 2019 10:59:15 +0200 Subject: [PATCH] Optimized ManageBackupCommand with #baseUserCount method New backup is not initialized if the source database does not have users --- .../command/commands/manage/ManageBackupCommand.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageBackupCommand.java b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageBackupCommand.java index 9bb2f9f18..916d3da5a 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageBackupCommand.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/command/commands/manage/ManageBackupCommand.java @@ -22,6 +22,7 @@ import com.djrapitops.plan.db.DBType; import com.djrapitops.plan.db.Database; import com.djrapitops.plan.db.SQLiteDB; import com.djrapitops.plan.db.access.transactions.BackupCopyTransaction; +import com.djrapitops.plan.db.sql.queries.AggregateQueries; import com.djrapitops.plan.system.database.DBSystem; import com.djrapitops.plan.system.locale.Locale; import com.djrapitops.plan.system.locale.lang.CmdHelpLang; @@ -42,8 +43,6 @@ import com.djrapitops.plugin.utilities.Verify; import javax.inject.Inject; import javax.inject.Singleton; import java.util.Arrays; -import java.util.Collection; -import java.util.UUID; /** * This command is used to backup a database to a .db file. @@ -127,15 +126,15 @@ public class ManageBackupCommand extends CommandNode { * @param copyFromDB Database you want to backup. */ private void createNewBackup(String dbName, Database copyFromDB) { + Integer userCount = copyFromDB.query(AggregateQueries.baseUserCount()); + if (userCount <= 0) { + return; + } SQLiteDB backupDB = null; try { String timeStamp = iso8601LongFormatter.apply(System.currentTimeMillis()); String fileName = dbName + "-backup-" + timeStamp; backupDB = sqliteFactory.usingFileCalled(fileName); - Collection uuids = copyFromDB.fetch().getSavedUUIDs(); - if (uuids.isEmpty()) { - return; - } backupDB.init(); backupDB.executeTransaction(new BackupCopyTransaction(copyFromDB)); } catch (DBException e) {