mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-26 02:57:52 +01:00
Optimized ManageBackupCommand with #baseUserCount method
New backup is not initialized if the source database does not have users
This commit is contained in:
parent
a99fe31b75
commit
fbb1bb72de
@ -22,6 +22,7 @@ import com.djrapitops.plan.db.DBType;
|
|||||||
import com.djrapitops.plan.db.Database;
|
import com.djrapitops.plan.db.Database;
|
||||||
import com.djrapitops.plan.db.SQLiteDB;
|
import com.djrapitops.plan.db.SQLiteDB;
|
||||||
import com.djrapitops.plan.db.access.transactions.BackupCopyTransaction;
|
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.database.DBSystem;
|
||||||
import com.djrapitops.plan.system.locale.Locale;
|
import com.djrapitops.plan.system.locale.Locale;
|
||||||
import com.djrapitops.plan.system.locale.lang.CmdHelpLang;
|
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.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This command is used to backup a database to a .db file.
|
* 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.
|
* @param copyFromDB Database you want to backup.
|
||||||
*/
|
*/
|
||||||
private void createNewBackup(String dbName, Database copyFromDB) {
|
private void createNewBackup(String dbName, Database copyFromDB) {
|
||||||
|
Integer userCount = copyFromDB.query(AggregateQueries.baseUserCount());
|
||||||
|
if (userCount <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
SQLiteDB backupDB = null;
|
SQLiteDB backupDB = null;
|
||||||
try {
|
try {
|
||||||
String timeStamp = iso8601LongFormatter.apply(System.currentTimeMillis());
|
String timeStamp = iso8601LongFormatter.apply(System.currentTimeMillis());
|
||||||
String fileName = dbName + "-backup-" + timeStamp;
|
String fileName = dbName + "-backup-" + timeStamp;
|
||||||
backupDB = sqliteFactory.usingFileCalled(fileName);
|
backupDB = sqliteFactory.usingFileCalled(fileName);
|
||||||
Collection<UUID> uuids = copyFromDB.fetch().getSavedUUIDs();
|
|
||||||
if (uuids.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
backupDB.init();
|
backupDB.init();
|
||||||
backupDB.executeTransaction(new BackupCopyTransaction(copyFromDB));
|
backupDB.executeTransaction(new BackupCopyTransaction(copyFromDB));
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user