Optimized ManageBackupCommand with #baseUserCount method

New backup is not initialized if the source database does not have users
This commit is contained in:
Rsl1122 2019-01-26 10:59:15 +02:00
parent a99fe31b75
commit fbb1bb72de

View File

@ -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<UUID> uuids = copyFromDB.fetch().getSavedUUIDs();
if (uuids.isEmpty()) {
return;
}
backupDB.init();
backupDB.executeTransaction(new BackupCopyTransaction(copyFromDB));
} catch (DBException e) {