-
Notifications
You must be signed in to change notification settings - Fork 34
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
90 additions
and
0 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
patches/removed/server/1.21/0018-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,90 @@ | ||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
From: =?UTF-8?q?=E3=84=97=E3=84=A0=CB=8B=20=E3=84=91=E3=84=A7=CB=8A?= | ||
<[email protected]> | ||
Date: Thu, 5 Jan 2023 09:08:17 +0800 | ||
Subject: [PATCH] Akarin: Save Json list asynchronously | ||
|
||
Original license: GPL v3 | ||
Original project: https://github.com/Akarin-project/Akarin | ||
Original project: https://github.com/Winds-Studio/Leaf | ||
|
||
diff --git a/src/main/java/net/minecraft/server/players/StoredUserList.java b/src/main/java/net/minecraft/server/players/StoredUserList.java | ||
index 7e133752ccb1ea7c0b4fa781feb1a88e2cfdcf6d..c06a0e8fe3f9a8f67e6a92e10ba9d8e47525bbfb 100644 | ||
--- a/src/main/java/net/minecraft/server/players/StoredUserList.java | ||
+++ b/src/main/java/net/minecraft/server/players/StoredUserList.java | ||
@@ -22,6 +22,7 @@ import java.util.Objects; | ||
import java.util.stream.Stream; | ||
import javax.annotation.Nullable; | ||
import net.minecraft.Util; | ||
+import io.papermc.paper.util.MCUtil; | ||
import net.minecraft.util.GsonHelper; | ||
import org.slf4j.Logger; | ||
|
||
@@ -103,37 +104,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 saveTask = ()->{ // 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 { | ||
+ BufferedWriter bufferedwriter = Files.newWriter(this.file, StandardCharsets.UTF_8); | ||
|
||
- try { | ||
- StoredUserList.GSON.toJson(jsonarray, bufferedwriter); | ||
- } catch (Throwable throwable) { | ||
- if (bufferedwriter != null) { | ||
try { | ||
+ StoredUserList.GSON.toJson(jsonarray, 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); | ||
} | ||
+ }catch (Exception e){ | ||
+ StoredUserList.LOGGER.warn("Failed to async save " + this.file, e); // Akarin - Save json list async | ||
} | ||
- | ||
- throw throwable; | ||
- } | ||
- | ||
- if (bufferedwriter != null) { | ||
- bufferedwriter.close(); | ||
- } | ||
- | ||
+ }; | ||
+ MCUtil.scheduleAsyncTask(saveTask); // Akarin - Save json list async | ||
} | ||
|
||
public void load() throws IOException { |