mirror of
https://github.com/PaperMC/Paper.git
synced 2025-02-17 18:47:40 +01:00
Async GameProfileCache saving
This commit is contained in:
parent
ba4eeb8a28
commit
cda878cf64
3 changed files with 37 additions and 7 deletions
paper-server/patches/sources/net/minecraft/server
|
@ -719,7 +719,7 @@
|
|||
+ } 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 - Perf: Async GameProfileCache saving
|
||||
+ }
|
||||
+ // Spigot end
|
||||
|
||||
|
|
|
@ -170,7 +170,7 @@
|
|||
DedicatedServer.LOGGER.info("Default game type: {}", dedicatedserverproperties.gamemode);
|
||||
InetAddress inetaddress = null;
|
||||
|
||||
@@ -156,10 +246,23 @@
|
||||
@@ -156,21 +246,34 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -195,7 +195,11 @@
|
|||
DedicatedServer.LOGGER.warn("To change this, set \"online-mode\" to \"true\" in the server.properties file.");
|
||||
}
|
||||
|
||||
@@ -170,7 +273,7 @@
|
||||
if (this.convertOldUsers()) {
|
||||
- this.getProfileCache().save();
|
||||
+ this.getProfileCache().save(false); // Paper - Perf: Async GameProfileCache saving
|
||||
}
|
||||
|
||||
if (!OldUsersConverter.serverReadyAfterUserconversion(this)) {
|
||||
return false;
|
||||
} else {
|
||||
|
|
|
@ -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
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue