2019-05-06 04:58:04 +02:00
|
|
|
From f91fbcf96f3da34af86e02ca8361b0d95c3d7a9e Mon Sep 17 00:00:00 2001
|
2016-05-17 03:14:28 +02:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Mon, 16 May 2016 20:47:41 -0400
|
|
|
|
Subject: [PATCH] Optimize UserCache / Thread Safe
|
|
|
|
|
|
|
|
Because Techable keeps complaining about how this isn't thread safe,
|
|
|
|
easier to do this than replace the entire thing.
|
|
|
|
|
|
|
|
Additionally, move Saving of the User cache to be done async, incase
|
|
|
|
the user never changed the default setting for Spigot's save on stop only.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
2019-05-06 04:58:04 +02:00
|
|
|
index e9fad2999d..d7071929b8 100644
|
2016-05-17 03:14:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
2019-05-06 04:58:04 +02:00
|
|
|
@@ -740,7 +740,7 @@ public abstract class MinecraftServer extends IAsyncTaskHandlerReentrant<TickTas
|
2016-05-17 03:14:28 +02:00
|
|
|
// Spigot start
|
|
|
|
if (org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly) {
|
|
|
|
LOGGER.info("Saving usercache.json");
|
2018-07-16 17:34:55 +02:00
|
|
|
- this.getUserCache().c();
|
|
|
|
+ this.getUserCache().c(false); // Paper
|
2016-05-17 03:14:28 +02:00
|
|
|
}
|
|
|
|
// Spigot end
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/UserCache.java b/src/main/java/net/minecraft/server/UserCache.java
|
2019-05-06 04:58:04 +02:00
|
|
|
index 41be5bf64e..cd8a652eb6 100644
|
2016-05-17 03:14:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/UserCache.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/UserCache.java
|
2019-01-01 04:15:55 +01:00
|
|
|
@@ -108,7 +108,7 @@ public class UserCache {
|
2016-05-23 04:14:17 +02:00
|
|
|
this.a(gameprofile, (Date) null);
|
|
|
|
}
|
|
|
|
|
|
|
|
- private void a(GameProfile gameprofile, Date date) {
|
|
|
|
+ private synchronized void a(GameProfile gameprofile, Date date) { // Paper - synchronize
|
|
|
|
UUID uuid = gameprofile.getId();
|
|
|
|
|
|
|
|
if (date == null) {
|
2019-01-01 04:15:55 +01:00
|
|
|
@@ -121,8 +121,9 @@ public class UserCache {
|
2018-07-16 17:34:55 +02:00
|
|
|
|
2019-01-01 04:15:55 +01:00
|
|
|
UserCache.UserCacheEntry usercache_usercacheentry = new UserCache.UserCacheEntry(gameprofile, date);
|
2016-05-17 03:14:28 +02:00
|
|
|
|
|
|
|
- if (this.e.containsKey(uuid)) {
|
|
|
|
+ //if (this.e.containsKey(uuid)) { // Paper
|
|
|
|
UserCache.UserCacheEntry usercache_usercacheentry1 = (UserCache.UserCacheEntry) this.e.get(uuid);
|
|
|
|
+ if (usercache_usercacheentry1 != null) { // Paper
|
|
|
|
|
|
|
|
this.d.remove(usercache_usercacheentry1.a().getName().toLowerCase(Locale.ROOT));
|
|
|
|
this.f.remove(gameprofile);
|
2019-01-01 04:15:55 +01:00
|
|
|
@@ -135,7 +136,7 @@ public class UserCache {
|
2016-05-23 04:14:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
- public GameProfile getProfile(String s) {
|
|
|
|
+ public synchronized GameProfile getProfile(String s) { // Paper - synchronize
|
|
|
|
String s1 = s.toLowerCase(Locale.ROOT);
|
|
|
|
UserCache.UserCacheEntry usercache_usercacheentry = (UserCache.UserCacheEntry) this.d.get(s1);
|
|
|
|
|
2019-01-01 04:15:55 +01:00
|
|
|
@@ -164,8 +165,9 @@ public class UserCache {
|
2016-05-23 04:14:17 +02:00
|
|
|
return usercache_usercacheentry == null ? null : usercache_usercacheentry.a();
|
|
|
|
}
|
|
|
|
|
2018-03-22 06:28:22 +01:00
|
|
|
+ @Nullable public GameProfile getProfile(UUID uuid) { return a(uuid); } // Paper - OBFHELPER
|
|
|
|
@Nullable
|
|
|
|
- public GameProfile a(UUID uuid) {
|
|
|
|
+ public synchronized GameProfile a(UUID uuid) { // Paper - synchronize
|
|
|
|
UserCache.UserCacheEntry usercache_usercacheentry = (UserCache.UserCacheEntry) this.e.get(uuid);
|
|
|
|
|
|
|
|
return usercache_usercacheentry == null ? null : usercache_usercacheentry.a();
|
2019-01-01 04:15:55 +01:00
|
|
|
@@ -220,8 +222,15 @@ public class UserCache {
|
2016-05-17 03:14:28 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
public void c() {
|
|
|
|
+ c(true);
|
|
|
|
+ }
|
|
|
|
+ public void c(boolean asyncSave) {
|
|
|
|
+ // Paper end
|
|
|
|
String s = this.b.toJson(this.a(org.spigotmc.SpigotConfig.userCacheCap));
|
2016-05-23 04:20:15 +02:00
|
|
|
+ Runnable save = () -> {
|
2016-05-17 03:14:28 +02:00
|
|
|
+
|
|
|
|
BufferedWriter bufferedwriter = null;
|
|
|
|
|
|
|
|
try {
|
2019-01-01 04:15:55 +01:00
|
|
|
@@ -235,6 +244,14 @@ public class UserCache {
|
2016-05-17 03:14:28 +02:00
|
|
|
} finally {
|
|
|
|
IOUtils.closeQuietly(bufferedwriter);
|
|
|
|
}
|
|
|
|
+ // Paper start
|
2016-05-23 04:20:15 +02:00
|
|
|
+ };
|
2016-05-17 03:14:28 +02:00
|
|
|
+ if (asyncSave) {
|
|
|
|
+ MCUtil.scheduleAsyncTask(save);
|
|
|
|
+ } else {
|
|
|
|
+ save.run();
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
--
|
2019-04-23 06:47:07 +02:00
|
|
|
2.21.0
|
2016-05-17 03:14:28 +02:00
|
|
|
|