This repository has been archived by the owner on Dec 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
79 additions
and
0 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
patches/server/0078-Akarin-Save-Json-list-asynchronously.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: 404Setup <153366651+404Setup@users.noreply.github.com> | ||
Date: Fri, 30 Aug 2024 16:30:18 +0800 | ||
Subject: [PATCH] Akarin: Save Json list asynchronously | ||
|
||
You can find the original code on https://github.com/Akarin-project/Akarin | ||
|
||
diff --git a/src/main/java/net/minecraft/server/players/StoredUserList.java b/src/main/java/net/minecraft/server/players/StoredUserList.java | ||
index c038da20b76c0b7b1c18471b20be01e849d29f3a..c5d000ac7595a78de98464aa689ad90ebe7ff94d 100644 | ||
--- a/src/main/java/net/minecraft/server/players/StoredUserList.java | ||
+++ b/src/main/java/net/minecraft/server/players/StoredUserList.java | ||
@@ -103,37 +103,43 @@ public abstract class StoredUserList<K, V extends StoredUserEntry<K>> { | ||
} | ||
|
||
public void save() throws IOException { | ||
- this.removeExpired(); // Paper - remove expired values before saving | ||
- JsonArray jsonarray = new JsonArray(); | ||
- Stream<JsonObject> stream = this.map.values().stream().map((jsonlistentry) -> { // CraftBukkit - decompile error | ||
- JsonObject jsonobject = new JsonObject(); | ||
+ Runnable run = () -> {// Akarin - Save json list async | ||
+ this.removeExpired(); // Paper - remove expired values before saving | ||
+ JsonArray jsonarray = new JsonArray(); | ||
+ Stream<JsonObject> stream = this.map.values().stream().map((jsonlistentry) -> { // CraftBukkit - decompile error | ||
+ JsonObject jsonobject = new JsonObject(); | ||
|
||
- Objects.requireNonNull(jsonlistentry); | ||
- return (JsonObject) Util.make(jsonobject, jsonlistentry::serialize); | ||
- }); | ||
+ Objects.requireNonNull(jsonlistentry); | ||
+ return (JsonObject) Util.make(jsonobject, jsonlistentry::serialize); | ||
+ }); | ||
|
||
- Objects.requireNonNull(jsonarray); | ||
- stream.forEach(jsonarray::add); | ||
- BufferedWriter bufferedwriter = Files.newWriter(this.file, StandardCharsets.UTF_8); | ||
+ Objects.requireNonNull(jsonarray); | ||
+ stream.forEach(jsonarray::add); | ||
+ try {// Akarin - Save json list async | ||
+ BufferedWriter bufferedwriter = Files.newWriter(this.file, StandardCharsets.UTF_8); | ||
|
||
- try { | ||
- StoredUserList.GSON.toJson(jsonarray, StoredUserList.GSON.newJsonWriter(bufferedwriter)); | ||
- } catch (Throwable throwable) { | ||
- if (bufferedwriter != null) { | ||
try { | ||
+ StoredUserList.GSON.toJson(jsonarray, StoredUserList.GSON.newJsonWriter(bufferedwriter)); | ||
+ } catch (Throwable throwable) { | ||
+ if (bufferedwriter != null) { | ||
+ try { | ||
+ bufferedwriter.close(); | ||
+ } catch (Throwable throwable1) { | ||
+ throwable.addSuppressed(throwable1); | ||
+ } | ||
+ } | ||
+ throw throwable; | ||
+ } | ||
+ if (bufferedwriter != null) { | ||
bufferedwriter.close(); | ||
- } catch (Throwable throwable1) { | ||
- throwable.addSuppressed(throwable1); | ||
} | ||
+ // Leaf start - Akarin - Save json list async | ||
+ } catch (Exception e) { | ||
+ StoredUserList.LOGGER.warn("Failed to async save " + this.file, e); | ||
} | ||
- | ||
- throw throwable; | ||
- } | ||
- | ||
- if (bufferedwriter != null) { | ||
- bufferedwriter.close(); | ||
- } | ||
- | ||
+ }; | ||
+ io.papermc.paper.util.MCUtil.scheduleAsyncTask(run); | ||
+ // Akarin end - Save json list async | ||
} | ||
|
||
public void load() throws IOException { |