Paper/patches/server/0098-Async-GameProfileCache-saving.patch
Noah van der Aa b8edb0e130
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#9648)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
6b34da8f SPIGOT-7467: Add getAddress to RemoteConsoleCommandSender

CraftBukkit Changes:
db4ba2897 SPIGOT-7467: Add getAddress to RemoteConsoleCommandSender
4f7ff4dec PR-1246: Add missing AbstractTestingBase to tests which need them
f70a7b68d SPIGOT-7465, MC-264979: Fresh installations print NoSuchFileException for server.properties
8ef7afef6 PR-1240: Call BlockGrowEvent for vines that are growing on additional sides of an existing vine block

Spigot Changes:
d2eba2c8 Rebuild patches
2023-08-28 13:05:48 +02:00

87 lines
3.9 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
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 0ee486f807d7c44e2252c4c744e29b506d916d9c..b5ededfb23980abca01ef25207cca95ad390a70d 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -932,7 +932,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
io.papermc.paper.chunk.system.io.RegionFileIOThread.close(true); // Paper // Paper - rewrite chunk system
diff --git a/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java b/src/main/java/net/minecraft/server/dedicated/DedicatedServer.java
index 2c2d492fdfafb1d2e4e962e6818bd9d7466347d5..131de2ca246cfbe4cb253e74cb05a73efbbcca73 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 d246563021c32127e570809f4d849b6a156f4dc6..225e15d686675e21969c4210fa38fef58d920355 100644
--- a/src/main/java/net/minecraft/server/players/GameProfileCache.java
+++ b/src/main/java/net/minecraft/server/players/GameProfileCache.java
@@ -127,7 +127,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() {
@@ -160,7 +160,7 @@ public class GameProfileCache {
}
if (flag && !org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly) { // Spigot - skip saving if disabled
- this.save();
+ this.save(true); // Paper
}
return optional;
@@ -274,7 +274,7 @@ public class GameProfileCache {
return arraylist;
}
- public void save() {
+ public void save(boolean asyncSave) { // Paper
JsonArray jsonarray = new JsonArray();
DateFormat dateformat = GameProfileCache.createDateFormat();
@@ -282,6 +282,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);
@@ -306,6 +307,14 @@ public class GameProfileCache {
} catch (IOException ioexception) {
;
}
+ // Paper start
+ };
+ if (asyncSave) {
+ io.papermc.paper.util.MCUtil.scheduleAsyncTask(save);
+ } else {
+ save.run();
+ }
+ // Paper end
}