diff options
author | Keuin <[email protected]> | 2020-12-26 12:48:28 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2020-12-26 12:48:28 +0800 |
commit | 55715b8b3fc8705e6eecbf835c8d441d3503fa7d (patch) | |
tree | 5ce4fe5e32219e8289bb61e18bc416d594cc0e79 /src/main | |
parent | 5adc0672b731970f75603b6bc386b731dcabe921 (diff) |
fix mongo spamming
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/keuin/blame/Blame.java | 20 | ||||
-rw-r--r-- | src/main/java/com/keuin/blame/data/transformer/TransformerManager.java | 4 |
2 files changed, 20 insertions, 4 deletions
diff --git a/src/main/java/com/keuin/blame/Blame.java b/src/main/java/com/keuin/blame/Blame.java index f620f73..744d920 100644 --- a/src/main/java/com/keuin/blame/Blame.java +++ b/src/main/java/com/keuin/blame/Blame.java @@ -18,6 +18,8 @@ import net.fabricmc.fabric.api.event.player.*; import net.minecraft.server.MinecraftServer; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; +import org.apache.logging.log4j.core.LoggerContext; +import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; @@ -55,7 +57,9 @@ public class Blame implements ModInitializer { private static void disableMongoSpamming() { Logger mongoLogger = Logger.getLogger("org.mongodb.driver"); - mongoLogger.setLevel(Level.WARNING); + mongoLogger.setLevel(Level.SEVERE); + ((LoggerContext) LoggerFactory.getILoggerFactory()).getLogger("org.mongodb.driver") + .setLevel(org.apache.logging.log4j.Level.ERROR); } private static void upgradeOldLogEntries() { @@ -66,11 +70,19 @@ public class Blame implements ModInitializer { // final MongoCollection<LogEntry> collection = db.getCollection( // DatabaseUtil.MONGO_CONFIG.getLogCollectionName(), LogEntry.class // ); +// collection.updateMany() // FindIterable<LogEntry> iterable = -// collection.find(Filters.ne(LogEntryNames.VERSION, TransformerManager.LATEST_VERSION)); -// List<LogEntry> +// collection.find(Filters.ne(LogEntryNames.VERSION, TransformerManager.LATEST_VERSION)) +// .showRecordId(true); // for (LogEntry logEntry : iterable) { -// iterable.batchSize(100). +// if (logEntry.version > TransformerManager.LATEST_VERSION) { +// logger.warning("Detected a newer entry in the database! " + +// "Downgrading of Blame is not supported and may cause " + +// "unexpected behaviour."); +// continue; +// } +// +// collection.updateOne(iterable.showRecordId()) // } // // } diff --git a/src/main/java/com/keuin/blame/data/transformer/TransformerManager.java b/src/main/java/com/keuin/blame/data/transformer/TransformerManager.java index e4db239..645c990 100644 --- a/src/main/java/com/keuin/blame/data/transformer/TransformerManager.java +++ b/src/main/java/com/keuin/blame/data/transformer/TransformerManager.java @@ -4,6 +4,7 @@ import com.keuin.blame.data.entry.LogEntry; import java.util.HashMap; import java.util.Map; +import java.util.Objects; public class TransformerManager { @@ -20,6 +21,9 @@ public class TransformerManager { } public static Object transformTo(int targetVersion, LogEntry baseEntry) { + Objects.requireNonNull(baseEntry); + if (baseEntry.version > targetVersion) + throw new RuntimeException("Downgrade is not supported."); LogEntry entry = baseEntry; for (int currentVersion = baseEntry.version; currentVersion != targetVersion; ++currentVersion) entry = transformerMap.get(currentVersion + 1).transform(entry); |