Paper/patches/server/0098-Async-GameProfileCache-saving.patch

87 lines
3.8 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Mon, 16 May 2016 20:47:41 -0400
2022-03-18 04:53:36 +01:00
Subject: [PATCH] Async GameProfileCache saving
2021-06-11 14:02:28 +02:00
2021-06-12 07:20:08 +02:00
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
2023-09-21 22:14:58 +02:00
index f5483f4d2c0339b505bd4a6512b23be2af79d9f7..6ab95b11eafe69ed0fd584e87ac0f0bb176ce180 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
2023-09-21 22:14:58 +02:00
@@ -933,7 +933,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
2021-06-11 14:02:28 +02:00
} catch (java.lang.InterruptedException ignored) {} // Paper
if (org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly) {
2021-06-12 07:20:08 +02:00
MinecraftServer.LOGGER.info("Saving usercache.json");
2021-06-11 14:02:28 +02:00
- this.getProfileCache().save();
2021-06-12 07:20:08 +02:00
+ this.getProfileCache().save(false); // Paper
2021-06-11 14:02:28 +02:00
}
// Spigot end
2023-09-21 22:14:58 +02:00
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
2023-09-21 22:14:58 +02:00
index 8d4fadc9c65636259bdbdba28bb8a3f8f4e25768..6cc085cf212994cd00dbabd4dd363fc5b3c97281 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
2022-12-07 19:52:24 +01:00
@@ -242,7 +242,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
2021-06-11 14:02:28 +02:00
}
if (this.convertOldUsers()) {
- this.getProfileCache().save();
2021-06-12 07:20:08 +02:00
+ this.getProfileCache().save(false); // Paper
2021-06-11 14:02:28 +02:00
}
if (!OldUsersConverter.serverReadyAfterUserconversion(this)) {
diff --git a/src/main/java/net/minecraft/server/players/GameProfileCache.java b/src/main/java/net/minecraft/server/players/GameProfileCache.java
2023-09-21 22:14:58 +02:00
index 7170f8cfd733708089495b51647659237bd10385..322e07adc556ee8131d40d89856574b185ee4c94 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/players/GameProfileCache.java
+++ b/src/main/java/net/minecraft/server/players/GameProfileCache.java
2023-09-21 22:14:58 +02:00
@@ -115,7 +115,7 @@ public class GameProfileCache {
2021-06-12 07:20:08 +02:00
GameProfileCache.GameProfileInfo usercache_usercacheentry = new GameProfileCache.GameProfileInfo(profile, date);
2021-06-11 14:02:28 +02:00
this.safeAdd(usercache_usercacheentry);
- if( !org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly ) this.save(); // Spigot - skip saving if disabled
2021-06-12 07:20:08 +02:00
+ if( !org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly ) this.save(true); // Spigot - skip saving if disabled // Paper - async
2021-06-11 14:02:28 +02:00
}
private long getNextOperation() {
2023-09-21 22:14:58 +02:00
@@ -148,7 +148,7 @@ public class GameProfileCache {
2021-06-11 14:02:28 +02:00
}
if (flag && !org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly) { // Spigot - skip saving if disabled
- this.save();
2021-06-12 07:20:08 +02:00
+ this.save(true); // Paper
2021-06-11 14:02:28 +02:00
}
2021-07-07 08:52:40 +02:00
return optional;
2023-09-21 22:14:58 +02:00
@@ -260,7 +260,7 @@ public class GameProfileCache {
2021-06-11 14:02:28 +02:00
return arraylist;
}
- public void save() {
2021-06-12 07:20:08 +02:00
+ public void save(boolean asyncSave) { // Paper
2021-06-11 14:02:28 +02:00
JsonArray jsonarray = new JsonArray();
2021-06-12 07:20:08 +02:00
DateFormat dateformat = GameProfileCache.createDateFormat();
2021-06-11 14:02:28 +02:00
2023-09-21 22:14:58 +02:00
@@ -268,6 +268,7 @@ public class GameProfileCache {
2021-06-12 07:20:08 +02:00
jsonarray.add(GameProfileCache.writeGameProfile(usercache_usercacheentry, dateformat));
2021-06-11 14:02:28 +02:00
});
String s = this.gson.toJson(jsonarray);
+ Runnable save = () -> { // Paper
try {
BufferedWriter bufferedwriter = Files.newWriter(this.file, StandardCharsets.UTF_8);
2023-09-21 22:14:58 +02:00
@@ -292,6 +293,14 @@ public class GameProfileCache {
2021-06-11 14:02:28 +02:00
} catch (IOException ioexception) {
;
}
+ // Paper start
+ };
+ if (asyncSave) {
+ io.papermc.paper.util.MCUtil.scheduleAsyncTask(save);
2021-06-11 14:02:28 +02:00
+ } else {
+ save.run();
+ }
+ // Paper end
2022-03-18 04:53:36 +01:00
2021-06-11 14:02:28 +02:00
}