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
|
2024-09-19 16:36:07 +02:00
|
|
|
index f16ade2019e58a9374a550f58113313c118c2f2b..10d69b48158460e5739d1e41a83fcaeec819fac6 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
|
2024-09-19 16:36:07 +02:00
|
|
|
@@ -998,7 +998,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();
|
2024-01-23 14:34:17 +01:00
|
|
|
+ this.getProfileCache().save(false); // Paper - Perf: Async GameProfileCache saving
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
// Spigot end
|
2024-01-24 13:07:40 +01: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
|
2024-06-13 19:30:39 +02:00
|
|
|
index 48107f8eb50483430053b990496862d71c9f8a3e..c1f41dcf49c75c3d69485c0e1ec821205438ed1e 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
|
2024-06-13 19:30:39 +02:00
|
|
|
@@ -270,7 +270,7 @@ public class DedicatedServer extends MinecraftServer implements ServerInterface
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.convertOldUsers()) {
|
|
|
|
- this.getProfileCache().save();
|
2024-01-23 14:34:17 +01:00
|
|
|
+ this.getProfileCache().save(false); // Paper - Perf: Async GameProfileCache saving
|
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
|
2024-04-24 03:25:14 +02:00
|
|
|
index f6e290bf4480da51512f8a166459687dad1f6a07..5b219b5eee0c5958b80093c9223feeed0dec830b 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-12-28 21:47:57 +01:00
|
|
|
@@ -117,7 +117,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
|
2024-01-23 14:34:17 +01:00
|
|
|
+ if( !org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly ) this.save(true); // Spigot - skip saving if disabled // Paper - Perf: Async GameProfileCache saving
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private long getNextOperation() {
|
2023-12-28 21:47:57 +01:00
|
|
|
@@ -150,7 +150,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();
|
2024-01-23 14:34:17 +01:00
|
|
|
+ this.save(true); // Paper - Perf: Async GameProfileCache saving
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
2021-07-07 08:52:40 +02:00
|
|
|
return optional;
|
2023-12-28 21:47:57 +01:00
|
|
|
@@ -262,7 +262,7 @@ public class GameProfileCache {
|
2024-04-24 03:25:14 +02:00
|
|
|
return list;
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- public void save() {
|
2024-01-23 14:34:17 +01:00
|
|
|
+ public void save(boolean asyncSave) { // Paper - Perf: Async GameProfileCache saving
|
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-12-28 21:47:57 +01:00
|
|
|
@@ -270,6 +270,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);
|
2024-01-23 14:34:17 +01:00
|
|
|
+ Runnable save = () -> { // Paper - Perf: Async GameProfileCache saving
|
2021-06-11 14:02:28 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
BufferedWriter bufferedwriter = Files.newWriter(this.file, StandardCharsets.UTF_8);
|
2023-12-28 21:47:57 +01:00
|
|
|
@@ -294,6 +295,14 @@ public class GameProfileCache {
|
2021-06-11 14:02:28 +02:00
|
|
|
} catch (IOException ioexception) {
|
|
|
|
;
|
|
|
|
}
|
2024-01-23 14:34:17 +01:00
|
|
|
+ // Paper start - Perf: Async GameProfileCache saving
|
2021-06-11 14:02:28 +02:00
|
|
|
+ };
|
|
|
|
+ if (asyncSave) {
|
2022-10-24 21:43:46 +02:00
|
|
|
+ io.papermc.paper.util.MCUtil.scheduleAsyncTask(save);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ } else {
|
|
|
|
+ save.run();
|
|
|
|
+ }
|
2024-01-23 14:34:17 +01:00
|
|
|
+ // Paper end - Perf: Async GameProfileCache saving
|
2022-03-18 04:53:36 +01:00
|
|
|
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
|