From 4d7be13c164db420c8dff8628e3fbcd94955710b Mon Sep 17 00:00:00 2001 From: Luck Date: Sun, 3 Jun 2018 20:46:50 +0100 Subject: [PATCH] Don't reload Sponge persisted subjects when a save is pending --- .../common/buffers/UpdateTaskBuffer.java | 2 +- .../storage/wrappings/PhasedStorage.java | 5 ---- .../service/persisted/PersistedSubject.java | 26 +++++++++++++++---- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/common/src/main/java/me/lucko/luckperms/common/buffers/UpdateTaskBuffer.java b/common/src/main/java/me/lucko/luckperms/common/buffers/UpdateTaskBuffer.java index 2e43d486..21351913 100644 --- a/common/src/main/java/me/lucko/luckperms/common/buffers/UpdateTaskBuffer.java +++ b/common/src/main/java/me/lucko/luckperms/common/buffers/UpdateTaskBuffer.java @@ -34,7 +34,7 @@ public class UpdateTaskBuffer extends BufferedRequest { private final LuckPermsPlugin plugin; public UpdateTaskBuffer(LuckPermsPlugin plugin) { - super(250L, TimeUnit.MILLISECONDS, plugin.getBootstrap().getScheduler()); + super(500L, TimeUnit.MILLISECONDS, plugin.getBootstrap().getScheduler()); this.plugin = plugin; } diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/wrappings/PhasedStorage.java b/common/src/main/java/me/lucko/luckperms/common/storage/wrappings/PhasedStorage.java index 4148281a..6252aa4d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/wrappings/PhasedStorage.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/wrappings/PhasedStorage.java @@ -54,11 +54,6 @@ public interface PhasedStorage extends Storage { new Class[]{PhasedStorage.class}, (proxy, method, args) -> { - // provide implementation of #noBuffer - if (method.getName().equals("noBuffer")) { - return delegate; - } - // direct delegation switch (method.getName()) { case "getDao": diff --git a/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubject.java b/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubject.java index c50aab67..4a485aa3 100644 --- a/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubject.java +++ b/sponge/src/main/java/me/lucko/luckperms/sponge/service/persisted/PersistedSubject.java @@ -70,6 +70,11 @@ public class PersistedSubject extends CalculatedSubject implements LPSubject { */ private final SaveBuffer saveBuffer; + /** + * If a save is pending for this subject + */ + private boolean pendingSave = false; + public PersistedSubject(LuckPermsService service, PersistedCollection parentCollection, String identifier) { super(service.getPlugin()); this.service = service; @@ -113,6 +118,10 @@ public class PersistedSubject extends CalculatedSubject implements LPSubject { * @param container the container to load from */ public void loadData(SubjectDataContainer container) { + if (this.pendingSave) { + return; + } + this.subjectData.setSave(false); container.applyToData(this.subjectData); this.subjectData.setSave(true); @@ -122,9 +131,20 @@ public class PersistedSubject extends CalculatedSubject implements LPSubject { * Requests that this subjects data is saved to disk */ public void save() { + this.pendingSave = true; this.saveBuffer.request(); } + void doSave() { + try { + this.service.getStorage().saveToFile(PersistedSubject.this); + } catch (IOException e) { + e.printStackTrace(); + } finally { + this.pendingSave = false; + } + } + @Override public Subject sponge() { if (this.spongeSubject == null) { @@ -170,11 +190,7 @@ public class PersistedSubject extends CalculatedSubject implements LPSubject { @Override protected Void perform() { - try { - PersistedSubject.this.service.getStorage().saveToFile(PersistedSubject.this); - } catch (IOException e) { - e.printStackTrace(); - } + doSave(); return null; } }