aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0098-Async-GameProfileCache-saving.patch
diff options
context:
space:
mode:
authorNoah van der Aa <[email protected]>2023-09-21 22:14:58 +0200
committerNoah van der Aa <[email protected]>2023-09-21 22:14:58 +0200
commit91671751e7ceff11d456ce337fcdec709b0791a1 (patch)
treea8c49db22ec99356546e189b0ce83c7d554ded9b /patches/server/0098-Async-GameProfileCache-saving.patch
parent20253f478fb4b1178de144f0fe9bbac7db9e04a8 (diff)
downloadPaper-91671751e7ceff11d456ce337fcdec709b0791a1.tar.gz
Paper-91671751e7ceff11d456ce337fcdec709b0791a1.zip
more more more work
Diffstat (limited to 'patches/server/0098-Async-GameProfileCache-saving.patch')
-rw-r--r--patches/server/0098-Async-GameProfileCache-saving.patch86
1 files changed, 86 insertions, 0 deletions
diff --git a/patches/server/0098-Async-GameProfileCache-saving.patch b/patches/server/0098-Async-GameProfileCache-saving.patch
new file mode 100644
index 0000000000..b4cacd70f8
--- /dev/null
+++ b/patches/server/0098-Async-GameProfileCache-saving.patch
@@ -0,0 +1,86 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Aikar <[email protected]>
+Date: Mon, 16 May 2016 20:47:41 -0400
+Subject: [PATCH] Async GameProfileCache saving
+
+
+diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
+index f5483f4d2c0339b505bd4a6512b23be2af79d9f7..6ab95b11eafe69ed0fd584e87ac0f0bb176ce180 100644
+--- a/src/main/java/net/minecraft/server/MinecraftServer.java
++++ b/src/main/java/net/minecraft/server/MinecraftServer.java
+@@ -933,7 +933,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
+ } catch (java.lang.InterruptedException ignored) {} // Paper
+ if (org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly) {
+ MinecraftServer.LOGGER.info("Saving usercache.json");
+- this.getProfileCache().save();
++ this.getProfileCache().save(false); // Paper
+ }
+ // Spigot end
+
+diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+index 8d4fadc9c65636259bdbdba28bb8a3f8f4e25768..6cc085cf212994cd00dbabd4dd363fc5b3c97281 100644
+--- a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
++++ b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
+@@ -242,7 +242,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
+ }
+
+ if (this.convertOldUsers()) {
+- this.getProfileCache().save();
++ this.getProfileCache().save(false); // Paper
+ }
+
+ 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
+index 7170f8cfd733708089495b51647659237bd10385..322e07adc556ee8131d40d89856574b185ee4c94 100644
+--- a/src/main/java/net/minecraft/server/players/GameProfileCache.java
++++ b/src/main/java/net/minecraft/server/players/GameProfileCache.java
+@@ -115,7 +115,7 @@ public class GameProfileCache {
+ GameProfileCache.GameProfileInfo usercache_usercacheentry = new GameProfileCache.GameProfileInfo(profile, date);
+
+ this.safeAdd(usercache_usercacheentry);
+- if( !org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly ) this.save(); // Spigot - skip saving if disabled
++ if( !org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly ) this.save(true); // Spigot - skip saving if disabled // Paper - async
+ }
+
+ private long getNextOperation() {
+@@ -148,7 +148,7 @@ public class GameProfileCache {
+ }
+
+ if (flag && !org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly) { // Spigot - skip saving if disabled
+- this.save();
++ this.save(true); // Paper
+ }
+
+ return optional;
+@@ -260,7 +260,7 @@ public class GameProfileCache {
+ return arraylist;
+ }
+
+- public void save() {
++ public void save(boolean asyncSave) { // Paper
+ JsonArray jsonarray = new JsonArray();
+ DateFormat dateformat = GameProfileCache.createDateFormat();
+
+@@ -268,6 +268,7 @@ public class GameProfileCache {
+ jsonarray.add(GameProfileCache.writeGameProfile(usercache_usercacheentry, dateformat));
+ });
+ String s = this.gson.toJson(jsonarray);
++ Runnable save = () -> { // Paper
+
+ try {
+ BufferedWriter bufferedwriter = Files.newWriter(this.file, StandardCharsets.UTF_8);
+@@ -292,6 +293,14 @@ public class GameProfileCache {
+ } catch (IOException ioexception) {
+ ;
+ }
++ // Paper start
++ };
++ if (asyncSave) {
++ io.papermc.paper.util.MCUtil.scheduleAsyncTask(save);
++ } else {
++ save.run();
++ }
++ // Paper end
+
+ }
+