Don't reload Sponge persisted subjects when a save is pending
This commit is contained in:
parent
8cf0f7da5f
commit
4d7be13c16
@ -34,7 +34,7 @@ public class UpdateTaskBuffer extends BufferedRequest<Void> {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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":
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user