mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-16 15:45:16 +01:00
Delete disabled extensions' data right after disabling them
Affects issues: - Close #2179
This commit is contained in:
parent
036ec23c08
commit
9c6085da86
@ -17,6 +17,7 @@
|
|||||||
package com.djrapitops.plan.storage.database.transactions.init;
|
package com.djrapitops.plan.storage.database.transactions.init;
|
||||||
|
|
||||||
import com.djrapitops.plan.identification.ServerUUID;
|
import com.djrapitops.plan.identification.ServerUUID;
|
||||||
|
import com.djrapitops.plan.settings.config.ExtensionSettings;
|
||||||
import com.djrapitops.plan.storage.database.queries.Query;
|
import com.djrapitops.plan.storage.database.queries.Query;
|
||||||
import com.djrapitops.plan.storage.database.queries.QueryStatement;
|
import com.djrapitops.plan.storage.database.queries.QueryStatement;
|
||||||
import com.djrapitops.plan.storage.database.sql.tables.*;
|
import com.djrapitops.plan.storage.database.sql.tables.*;
|
||||||
@ -38,10 +39,12 @@ import static com.djrapitops.plan.storage.database.sql.building.Sql.*;
|
|||||||
*/
|
*/
|
||||||
public class RemoveOldExtensionsTransaction extends ThrowawayTransaction {
|
public class RemoveOldExtensionsTransaction extends ThrowawayTransaction {
|
||||||
|
|
||||||
|
private final ExtensionSettings extensionSettings;
|
||||||
private final long deleteOlder;
|
private final long deleteOlder;
|
||||||
private final ServerUUID serverUUID;
|
private final ServerUUID serverUUID;
|
||||||
|
|
||||||
public RemoveOldExtensionsTransaction(long deleteAfterMs, ServerUUID serverUUID) {
|
public RemoveOldExtensionsTransaction(ExtensionSettings extensionSettings, long deleteAfterMs, ServerUUID serverUUID) {
|
||||||
|
this.extensionSettings = extensionSettings;
|
||||||
deleteOlder = System.currentTimeMillis() - deleteAfterMs;
|
deleteOlder = System.currentTimeMillis() - deleteAfterMs;
|
||||||
this.serverUUID = serverUUID;
|
this.serverUUID = serverUUID;
|
||||||
}
|
}
|
||||||
@ -120,23 +123,27 @@ public class RemoveOldExtensionsTransaction extends ThrowawayTransaction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Query<Collection<Integer>> inactiveProviderIDsQuery() {
|
private Query<Collection<Integer>> inactiveProviderIDsQuery() {
|
||||||
String sql = SELECT + "pr." + ExtensionProviderTable.ID +
|
String sql = SELECT + "pr." + ExtensionProviderTable.ID + ',' +
|
||||||
|
"pl." + ExtensionPluginTable.LAST_UPDATED + ',' +
|
||||||
|
"pl." + ExtensionPluginTable.PLUGIN_NAME +
|
||||||
FROM + ExtensionProviderTable.TABLE_NAME + " pr" +
|
FROM + ExtensionProviderTable.TABLE_NAME + " pr" +
|
||||||
INNER_JOIN + ExtensionPluginTable.TABLE_NAME + " pl on pl." + ExtensionPluginTable.ID + "=pr." + ExtensionProviderTable.PLUGIN_ID +
|
INNER_JOIN + ExtensionPluginTable.TABLE_NAME + " pl on pl." + ExtensionPluginTable.ID + "=pr." + ExtensionProviderTable.PLUGIN_ID +
|
||||||
WHERE + ExtensionPluginTable.LAST_UPDATED + "<?" +
|
WHERE + ExtensionPluginTable.SERVER_UUID + "=?";
|
||||||
AND + ExtensionPluginTable.SERVER_UUID + "=?";
|
|
||||||
return new QueryStatement<Collection<Integer>>(sql, 100) {
|
return new QueryStatement<Collection<Integer>>(sql, 100) {
|
||||||
@Override
|
@Override
|
||||||
public void prepare(PreparedStatement statement) throws SQLException {
|
public void prepare(PreparedStatement statement) throws SQLException {
|
||||||
statement.setLong(1, deleteOlder);
|
statement.setString(1, serverUUID.toString());
|
||||||
statement.setString(2, serverUUID.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Integer> processResults(ResultSet set) throws SQLException {
|
public Collection<Integer> processResults(ResultSet set) throws SQLException {
|
||||||
Collection<Integer> providerIds = new HashSet<>();
|
Collection<Integer> providerIds = new HashSet<>();
|
||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
providerIds.add(set.getInt(ExtensionProviderTable.ID));
|
boolean manuallyDisabled = !extensionSettings.isEnabled(set.getString(ExtensionPluginTable.PLUGIN_NAME));
|
||||||
|
boolean dataIsOld = set.getLong(ExtensionPluginTable.LAST_UPDATED) < deleteOlder;
|
||||||
|
if (manuallyDisabled || dataIsOld) {
|
||||||
|
providerIds.add(set.getInt(ExtensionProviderTable.ID));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return providerIds;
|
return providerIds;
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ public class DBCleanTask extends TaskSystem.Task {
|
|||||||
// This is needed since the last updated number is updated at reload and it would lead to all data
|
// This is needed since the last updated number is updated at reload and it would lead to all data
|
||||||
// for plugins being deleted all the time.
|
// for plugins being deleted all the time.
|
||||||
if (System.currentTimeMillis() - lastReload <= deleteExtensionDataAfter) {
|
if (System.currentTimeMillis() - lastReload <= deleteExtensionDataAfter) {
|
||||||
database.executeTransaction(new RemoveOldExtensionsTransaction(deleteExtensionDataAfter, serverInfo.getServerUUID()));
|
database.executeTransaction(new RemoveOldExtensionsTransaction(config.getExtensionSettings(), deleteExtensionDataAfter, serverInfo.getServerUUID()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (DBOpException e) {
|
} catch (DBOpException e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user