Don't reload Sponge persisted subjects when a save is pending

This commit is contained in:
Luck 2018-06-03 20:46:50 +01:00
parent 8cf0f7da5f
commit 4d7be13c16
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
3 changed files with 22 additions and 11 deletions

View File

@ -34,7 +34,7 @@ public class UpdateTaskBuffer extends BufferedRequest<Void> {
private final LuckPermsPlugin plugin; private final LuckPermsPlugin plugin;
public UpdateTaskBuffer(LuckPermsPlugin plugin) { public UpdateTaskBuffer(LuckPermsPlugin plugin) {
super(250L, TimeUnit.MILLISECONDS, plugin.getBootstrap().getScheduler()); super(500L, TimeUnit.MILLISECONDS, plugin.getBootstrap().getScheduler());
this.plugin = plugin; this.plugin = plugin;
} }

View File

@ -54,11 +54,6 @@ public interface PhasedStorage extends Storage {
new Class[]{PhasedStorage.class}, new Class[]{PhasedStorage.class},
(proxy, method, args) -> { (proxy, method, args) -> {
// provide implementation of #noBuffer
if (method.getName().equals("noBuffer")) {
return delegate;
}
// direct delegation // direct delegation
switch (method.getName()) { switch (method.getName()) {
case "getDao": case "getDao":

View File

@ -70,6 +70,11 @@ public class PersistedSubject extends CalculatedSubject implements LPSubject {
*/ */
private final SaveBuffer saveBuffer; private final SaveBuffer saveBuffer;
/**
* If a save is pending for this subject
*/
private boolean pendingSave = false;
public PersistedSubject(LuckPermsService service, PersistedCollection parentCollection, String identifier) { public PersistedSubject(LuckPermsService service, PersistedCollection parentCollection, String identifier) {
super(service.getPlugin()); super(service.getPlugin());
this.service = service; this.service = service;
@ -113,6 +118,10 @@ public class PersistedSubject extends CalculatedSubject implements LPSubject {
* @param container the container to load from * @param container the container to load from
*/ */
public void loadData(SubjectDataContainer container) { public void loadData(SubjectDataContainer container) {
if (this.pendingSave) {
return;
}
this.subjectData.setSave(false); this.subjectData.setSave(false);
container.applyToData(this.subjectData); container.applyToData(this.subjectData);
this.subjectData.setSave(true); this.subjectData.setSave(true);
@ -122,9 +131,20 @@ public class PersistedSubject extends CalculatedSubject implements LPSubject {
* Requests that this subjects data is saved to disk * Requests that this subjects data is saved to disk
*/ */
public void save() { public void save() {
this.pendingSave = true;
this.saveBuffer.request(); this.saveBuffer.request();
} }
void doSave() {
try {
this.service.getStorage().saveToFile(PersistedSubject.this);
} catch (IOException e) {
e.printStackTrace();
} finally {
this.pendingSave = false;
}
}
@Override @Override
public Subject sponge() { public Subject sponge() {
if (this.spongeSubject == null) { if (this.spongeSubject == null) {
@ -170,11 +190,7 @@ public class PersistedSubject extends CalculatedSubject implements LPSubject {
@Override @Override
protected Void perform() { protected Void perform() {
try { doSave();
PersistedSubject.this.service.getStorage().saveToFile(PersistedSubject.this);
} catch (IOException e) {
e.printStackTrace();
}
return null; return null;
} }
} }