Lazily load contexts cache for Sponge subjects (#1005)

This commit is contained in:
Luck 2018-05-17 18:12:20 +01:00
parent 45e2b7b12f
commit ed3b5a3cf1
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
2 changed files with 22 additions and 10 deletions

View File

@ -54,20 +54,26 @@ public final class SubjectProxy implements Subject, ProxiedSubject {
private final LPPermissionService service;
private final LPSubjectReference ref;
private final ContextsCache<Subject> contextsCache;
private ContextsCache<Subject> contextsCache = null;
public SubjectProxy(LPPermissionService service, LPSubjectReference ref) {
this.service = service;
this.ref = ref;
ContextManager<Subject> contextManager = (ContextManager<Subject>) service.getPlugin().getContextManager();
this.contextsCache = contextManager.getCacheFor(this);
}
private CompletableFuture<LPSubject> handle() {
return this.ref.resolveLp();
}
// lazy init
private ContextsCache<Subject> getContextsCache() {
if (this.contextsCache == null) {
ContextManager<Subject> contextManager = (ContextManager<Subject>) this.service.getPlugin().getContextManager();
this.contextsCache = contextManager.getCacheFor(this);
}
return this.contextsCache;
}
@Nonnull
@Override
public LPSubjectReference asSubjectReference() {
@ -164,7 +170,7 @@ public final class SubjectProxy implements Subject, ProxiedSubject {
@Nonnull
@Override
public Set<Context> getActiveContexts() {
return CompatibilityUtil.convertContexts(this.contextsCache.getContextSet());
return CompatibilityUtil.convertContexts(getContextsCache().getContextSet());
}
@Override

View File

@ -54,20 +54,26 @@ public final class SubjectProxy implements Subject, ProxiedSubject {
private final LPPermissionService service;
private final LPSubjectReference ref;
private final ContextsCache<Subject> contextsCache;
private ContextsCache<Subject> contextsCache;
public SubjectProxy(LPPermissionService service, LPSubjectReference ref) {
this.service = service;
this.ref = ref;
ContextManager<Subject> contextManager = (ContextManager<Subject>) service.getPlugin().getContextManager();
this.contextsCache = contextManager.getCacheFor(this);
}
private CompletableFuture<LPSubject> handle() {
return this.ref.resolveLp();
}
// lazy init
private ContextsCache<Subject> getContextsCache() {
if (this.contextsCache == null) {
ContextManager<Subject> contextManager = (ContextManager<Subject>) this.service.getPlugin().getContextManager();
this.contextsCache = contextManager.getCacheFor(this);
}
return this.contextsCache;
}
@Nonnull
@Override
public LPSubjectReference asSubjectReference() {
@ -165,7 +171,7 @@ public final class SubjectProxy implements Subject, ProxiedSubject {
@Nonnull
@Override
public Set<Context> getActiveContexts() {
return CompatibilityUtil.convertContexts(this.contextsCache.getContextSet());
return CompatibilityUtil.convertContexts(getContextsCache().getContextSet());
}
@Override