Search in sources :

Example 1 with RemoveDuplicateUserInfoTransaction

use of com.djrapitops.plan.storage.database.transactions.init.RemoveDuplicateUserInfoTransaction in project Plan by plan-player-analytics.

the class UserInfoQueriesTest method cleanRemovesOnlyDuplicatedUserInfo.

@Test
default void cleanRemovesOnlyDuplicatedUserInfo() throws ExecutionException, InterruptedException {
    // Store one duplicate
    db().executeTransaction(new Transaction() {

        @Override
        protected void performOperations() {
            execute(DataStoreQueries.registerUserInfo(playerUUID, 0L, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME.get()));
            execute(DataStoreQueries.registerUserInfo(playerUUID, 0L, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME.get()));
            execute(DataStoreQueries.registerUserInfo(player2UUID, 0L, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME.get()));
        }
    }).get();
    db().executeTransaction(new RemoveDuplicateUserInfoTransaction());
    Set<UserInfo> found = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
    assertEquals(Collections.singleton(new UserInfo(playerUUID, serverUUID(), 0, false, TestConstants.GET_PLAYER_HOSTNAME.get(), false)), found);
    Set<UserInfo> found2 = db().query(UserInfoQueries.fetchUserInformationOfUser(player2UUID));
    assertEquals(Collections.singleton(new UserInfo(player2UUID, serverUUID(), 0, false, TestConstants.GET_PLAYER_HOSTNAME.get(), false)), found2);
}
Also used : Transaction(com.djrapitops.plan.storage.database.transactions.Transaction) RemoveDuplicateUserInfoTransaction(com.djrapitops.plan.storage.database.transactions.init.RemoveDuplicateUserInfoTransaction) RemoveEverythingTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction) StoreServerInformationTransaction(com.djrapitops.plan.storage.database.transactions.StoreServerInformationTransaction) RemoveDuplicateUserInfoTransaction(com.djrapitops.plan.storage.database.transactions.init.RemoveDuplicateUserInfoTransaction) UserInfo(com.djrapitops.plan.gathering.domain.UserInfo) Test(org.junit.jupiter.api.Test)

Example 2 with RemoveDuplicateUserInfoTransaction

use of com.djrapitops.plan.storage.database.transactions.init.RemoveDuplicateUserInfoTransaction in project Plan by plan-player-analytics.

the class DBCleanTask method run.

@Override
public void run() {
    Database database = dbSystem.getDatabase();
    try {
        if (database.getState() != Database.State.CLOSED) {
            database.executeTransaction(new RemoveOldSampledDataTransaction(serverInfo.getServerUUID(), config.get(TimeSettings.DELETE_TPS_DATA_AFTER), config.get(TimeSettings.DELETE_PING_DATA_AFTER)));
            database.executeTransaction(new RemoveDuplicateUserInfoTransaction());
            database.executeTransaction(new RemoveUnsatisfiedConditionalPlayerResultsTransaction());
            database.executeTransaction(new RemoveUnsatisfiedConditionalServerResultsTransaction());
            int removed = cleanOldPlayers(database);
            if (removed > 0) {
                logger.info(locale.getString(PluginLang.DB_NOTIFY_CLEAN, removed));
            }
            Long deleteExtensionDataAfter = config.get(TimeSettings.DELETE_EXTENSION_DATA_AFTER);
            Long databaseCleanPeriod = config.get(TimeSettings.CLEAN_DATABASE_PERIOD);
            if (databaseCleanPeriod > deleteExtensionDataAfter) {
                logger.warn("Data of Disabled Extensions can not be cleaned due to " + TimeSettings.CLEAN_DATABASE_PERIOD.getPath() + " being larger than " + TimeSettings.DELETE_EXTENSION_DATA_AFTER.getPath());
            }
            // for plugins being deleted all the time.
            if (System.currentTimeMillis() - lastReload <= deleteExtensionDataAfter) {
                database.executeTransaction(new RemoveOldExtensionsTransaction(config.getExtensionSettings(), deleteExtensionDataAfter, serverInfo.getServerUUID()));
            }
        }
    } catch (DBOpException e) {
        errorLogger.error(e);
        cancel();
    }
}
Also used : DBOpException(com.djrapitops.plan.exceptions.database.DBOpException) RemoveUnsatisfiedConditionalPlayerResultsTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalPlayerResultsTransaction) RemoveOldExtensionsTransaction(com.djrapitops.plan.storage.database.transactions.init.RemoveOldExtensionsTransaction) RemoveOldSampledDataTransaction(com.djrapitops.plan.storage.database.transactions.init.RemoveOldSampledDataTransaction) RemoveUnsatisfiedConditionalServerResultsTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalServerResultsTransaction) Database(com.djrapitops.plan.storage.database.Database) RemoveDuplicateUserInfoTransaction(com.djrapitops.plan.storage.database.transactions.init.RemoveDuplicateUserInfoTransaction)

Aggregations

RemoveDuplicateUserInfoTransaction (com.djrapitops.plan.storage.database.transactions.init.RemoveDuplicateUserInfoTransaction)2 DBOpException (com.djrapitops.plan.exceptions.database.DBOpException)1 RemoveUnsatisfiedConditionalPlayerResultsTransaction (com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalPlayerResultsTransaction)1 RemoveUnsatisfiedConditionalServerResultsTransaction (com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalServerResultsTransaction)1 UserInfo (com.djrapitops.plan.gathering.domain.UserInfo)1 Database (com.djrapitops.plan.storage.database.Database)1 StoreServerInformationTransaction (com.djrapitops.plan.storage.database.transactions.StoreServerInformationTransaction)1 Transaction (com.djrapitops.plan.storage.database.transactions.Transaction)1 RemoveEverythingTransaction (com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction)1 RemoveOldExtensionsTransaction (com.djrapitops.plan.storage.database.transactions.init.RemoveOldExtensionsTransaction)1 RemoveOldSampledDataTransaction (com.djrapitops.plan.storage.database.transactions.init.RemoveOldSampledDataTransaction)1 Test (org.junit.jupiter.api.Test)1