2017-08-03 22:36:06 +08:00
|
|
|
From 6c71a3974c2ab7d7adbbd06a63923019bdd64254 Mon Sep 17 00:00:00 2001
|
2016-05-17 09:14:28 +08: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
|
2017-08-03 22:36:06 +08:00
|
|
|
index 948a04491..9e43646eb 100644
|
2016-05-17 09:14:28 +08:00
|
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
2017-08-03 22:36:06 +08:00
|
|
|
@@ -528,7 +528,7 @@ public abstract class MinecraftServer implements ICommandListener, Runnable, IAs
|
2016-05-17 09:14:28 +08:00
|
|
|
// Spigot start
|
|
|
|
if (org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly) {
|
|
|
|
LOGGER.info("Saving usercache.json");
|
2016-11-17 10:23:38 +08:00
|
|
|
- this.Y.c();
|
|
|
|
+ this.Y.c(false); // Paper
|
2016-05-17 09:14:28 +08:00
|
|
|
}
|
|
|
|
// Spigot end
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/UserCache.java b/src/main/java/net/minecraft/server/UserCache.java
|
2017-08-03 22:36:06 +08:00
|
|
|
index 487fc11f1..924dc63a4 100644
|
2016-05-17 09:14:28 +08:00
|
|
|
--- a/src/main/java/net/minecraft/server/UserCache.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/UserCache.java
|
2017-05-15 02:05:01 +08:00
|
|
|
@@ -109,7 +109,7 @@ public class UserCache {
|
2016-05-23 10:14:17 +08: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) {
|
2017-05-15 02:05:01 +08:00
|
|
|
@@ -123,8 +123,9 @@ public class UserCache {
|
2016-05-17 09:14:28 +08:00
|
|
|
String s = gameprofile.getName().toLowerCase(Locale.ROOT);
|
|
|
|
UserCache.UserCacheEntry usercache_usercacheentry = new UserCache.UserCacheEntry(gameprofile, date, null);
|
|
|
|
|
|
|
|
- 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);
|
2017-05-15 02:05:01 +08:00
|
|
|
@@ -137,7 +138,7 @@ public class UserCache {
|
2016-05-23 10:14:17 +08: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);
|
|
|
|
|
2017-05-15 02:05:01 +08:00
|
|
|
@@ -166,7 +167,7 @@ public class UserCache {
|
2016-05-23 10:14:17 +08:00
|
|
|
return usercache_usercacheentry == null ? null : usercache_usercacheentry.a();
|
|
|
|
}
|
|
|
|
|
|
|
|
- public String[] a() {
|
|
|
|
+ public synchronized String[] a() { // Paper - synchronize
|
|
|
|
ArrayList arraylist = Lists.newArrayList(this.d.keySet());
|
|
|
|
|
|
|
|
return (String[]) arraylist.toArray(new String[arraylist.size()]);
|
2017-05-15 02:05:01 +08:00
|
|
|
@@ -228,8 +229,15 @@ public class UserCache {
|
2016-05-17 09:14:28 +08: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 10:20:15 +08:00
|
|
|
+ Runnable save = () -> {
|
2016-05-17 09:14:28 +08:00
|
|
|
+
|
|
|
|
BufferedWriter bufferedwriter = null;
|
|
|
|
|
|
|
|
try {
|
2017-05-15 02:05:01 +08:00
|
|
|
@@ -243,6 +251,14 @@ public class UserCache {
|
2016-05-17 09:14:28 +08:00
|
|
|
} finally {
|
|
|
|
IOUtils.closeQuietly(bufferedwriter);
|
|
|
|
}
|
|
|
|
+ // Paper start
|
2016-05-23 10:20:15 +08:00
|
|
|
+ };
|
2016-05-17 09:14:28 +08:00
|
|
|
+ if (asyncSave) {
|
|
|
|
+ MCUtil.scheduleAsyncTask(save);
|
|
|
|
+ } else {
|
|
|
|
+ save.run();
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
--
|
2017-08-03 22:36:06 +08:00
|
|
|
2.13.3.windows.1
|
2016-05-17 09:14:28 +08:00
|
|
|
|