Async GameProfileCache saving
This commit is contained in:
parent
ba4eeb8a28
commit
cda878cf64
3 changed files with 37 additions and 7 deletions
|
@ -719,7 +719,7 @@
|
||||||
+ } catch (java.lang.InterruptedException ignored) {} // Paper
|
+ } catch (java.lang.InterruptedException ignored) {} // Paper
|
||||||
+ if (org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly) {
|
+ if (org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly) {
|
||||||
+ MinecraftServer.LOGGER.info("Saving usercache.json");
|
+ MinecraftServer.LOGGER.info("Saving usercache.json");
|
||||||
+ this.getProfileCache().save();
|
+ this.getProfileCache().save(false); // Paper - Perf: Async GameProfileCache saving
|
||||||
+ }
|
+ }
|
||||||
+ // Spigot end
|
+ // Spigot end
|
||||||
|
|
||||||
|
|
|
@ -170,7 +170,7 @@
|
||||||
DedicatedServer.LOGGER.info("Default game type: {}", dedicatedserverproperties.gamemode);
|
DedicatedServer.LOGGER.info("Default game type: {}", dedicatedserverproperties.gamemode);
|
||||||
InetAddress inetaddress = null;
|
InetAddress inetaddress = null;
|
||||||
|
|
||||||
@@ -156,10 +246,23 @@
|
@@ -156,21 +246,34 @@
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,7 +195,11 @@
|
||||||
DedicatedServer.LOGGER.warn("To change this, set \"online-mode\" to \"true\" in the server.properties file.");
|
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)) {
|
if (!OldUsersConverter.serverReadyAfterUserconversion(this)) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -14,11 +14,11 @@
|
||||||
|
|
||||||
this.safeAdd(usercache_usercacheentry);
|
this.safeAdd(usercache_usercacheentry);
|
||||||
- this.save();
|
- 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() {
|
private long getNextOperation() {
|
||||||
@@ -142,14 +142,14 @@
|
@@ -142,15 +142,15 @@
|
||||||
usercache_usercacheentry.setLastAccess(this.getNextOperation());
|
usercache_usercacheentry.setLastAccess(this.getNextOperation());
|
||||||
optional = Optional.of(usercache_usercacheentry.getProfile());
|
optional = Optional.of(usercache_usercacheentry.getProfile());
|
||||||
} else {
|
} else {
|
||||||
|
@ -31,10 +31,12 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
- if (flag) {
|
- if (flag) {
|
||||||
|
- this.save();
|
||||||
+ if (flag && !org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly) { // Spigot - skip saving if disabled
|
+ 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 @@
|
@@ -208,7 +208,7 @@
|
||||||
|
|
||||||
label54:
|
label54:
|
||||||
|
@ -65,7 +67,12 @@
|
||||||
} catch (JsonParseException | IOException ioexception) {
|
} catch (JsonParseException | IOException ioexception) {
|
||||||
GameProfileCache.LOGGER.warn("Failed to load profile cache {}", this.file, 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();
|
JsonArray jsonarray = new JsonArray();
|
||||||
DateFormat dateformat = GameProfileCache.createDateFormat();
|
DateFormat dateformat = GameProfileCache.createDateFormat();
|
||||||
|
|
||||||
|
@ -74,3 +81,22 @@
|
||||||
jsonarray.add(GameProfileCache.writeGameProfile(usercache_usercacheentry, dateformat));
|
jsonarray.add(GameProfileCache.writeGameProfile(usercache_usercacheentry, dateformat));
|
||||||
});
|
});
|
||||||
String s = this.gson.toJson(jsonarray);
|
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
Add a link
Reference in a new issue