Async GameProfileCache saving

This commit is contained in:
Aikar
2016-05-16 20:47:41 -04:00
parent ba4eeb8a28
commit cda878cf64
3 changed files with 37 additions and 7 deletions

View File

@@ -14,11 +14,11 @@
this.safeAdd(usercache_usercacheentry);
- this.save();
+ 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 - Perf: Async GameProfileCache saving
}
private long getNextOperation() {
@@ -142,14 +142,14 @@
@@ -142,15 +142,15 @@
usercache_usercacheentry.setLastAccess(this.getNextOperation());
optional = Optional.of(usercache_usercacheentry.getProfile());
} else {
@@ -31,10 +31,12 @@
}
- if (flag) {
- this.save();
+ if (flag && !org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly) { // Spigot - skip saving if disabled
this.save();
+ this.save(true); // Paper - Perf: Async GameProfileCache saving
}
return optional;
@@ -208,7 +208,7 @@
label54:
@@ -65,7 +67,12 @@
} catch (JsonParseException | IOException ioexception) {
GameProfileCache.LOGGER.warn("Failed to load profile cache {}", this.file, ioexception);
}
@@ -261,7 +266,7 @@
@@ -257,14 +262,15 @@
return list;
}
- public void save() {
+ public void save(boolean asyncSave) { // Paper - Perf: Async GameProfileCache saving
JsonArray jsonarray = new JsonArray();
DateFormat dateformat = GameProfileCache.createDateFormat();
@@ -74,3 +81,22 @@
jsonarray.add(GameProfileCache.writeGameProfile(usercache_usercacheentry, dateformat));
});
String s = this.gson.toJson(jsonarray);
+ Runnable save = () -> { // Paper - Perf: Async GameProfileCache saving
try {
BufferedWriter bufferedwriter = Files.newWriter(this.file, StandardCharsets.UTF_8);
@@ -289,6 +295,14 @@
} catch (IOException ioexception) {
;
}
+ // Paper start - Perf: Async GameProfileCache saving
+ };
+ if (asyncSave) {
+ io.papermc.paper.util.MCUtil.scheduleAsyncTask(save);
+ } else {
+ save.run();
+ }
+ // Paper end - Perf: Async GameProfileCache saving
}