Lazily load contexts cache for Sponge subjects (#1005)
This commit is contained in:
parent
45e2b7b12f
commit
ed3b5a3cf1
@ -54,20 +54,26 @@ public final class SubjectProxy implements Subject, ProxiedSubject {
|
|||||||
private final LPPermissionService service;
|
private final LPPermissionService service;
|
||||||
private final LPSubjectReference ref;
|
private final LPSubjectReference ref;
|
||||||
|
|
||||||
private final ContextsCache<Subject> contextsCache;
|
private ContextsCache<Subject> contextsCache = null;
|
||||||
|
|
||||||
public SubjectProxy(LPPermissionService service, LPSubjectReference ref) {
|
public SubjectProxy(LPPermissionService service, LPSubjectReference ref) {
|
||||||
this.service = service;
|
this.service = service;
|
||||||
this.ref = ref;
|
this.ref = ref;
|
||||||
|
|
||||||
ContextManager<Subject> contextManager = (ContextManager<Subject>) service.getPlugin().getContextManager();
|
|
||||||
this.contextsCache = contextManager.getCacheFor(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private CompletableFuture<LPSubject> handle() {
|
private CompletableFuture<LPSubject> handle() {
|
||||||
return this.ref.resolveLp();
|
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
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public LPSubjectReference asSubjectReference() {
|
public LPSubjectReference asSubjectReference() {
|
||||||
@ -164,7 +170,7 @@ public final class SubjectProxy implements Subject, ProxiedSubject {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Set<Context> getActiveContexts() {
|
public Set<Context> getActiveContexts() {
|
||||||
return CompatibilityUtil.convertContexts(this.contextsCache.getContextSet());
|
return CompatibilityUtil.convertContexts(getContextsCache().getContextSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -54,20 +54,26 @@ public final class SubjectProxy implements Subject, ProxiedSubject {
|
|||||||
private final LPPermissionService service;
|
private final LPPermissionService service;
|
||||||
private final LPSubjectReference ref;
|
private final LPSubjectReference ref;
|
||||||
|
|
||||||
private final ContextsCache<Subject> contextsCache;
|
private ContextsCache<Subject> contextsCache;
|
||||||
|
|
||||||
public SubjectProxy(LPPermissionService service, LPSubjectReference ref) {
|
public SubjectProxy(LPPermissionService service, LPSubjectReference ref) {
|
||||||
this.service = service;
|
this.service = service;
|
||||||
this.ref = ref;
|
this.ref = ref;
|
||||||
|
|
||||||
ContextManager<Subject> contextManager = (ContextManager<Subject>) service.getPlugin().getContextManager();
|
|
||||||
this.contextsCache = contextManager.getCacheFor(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private CompletableFuture<LPSubject> handle() {
|
private CompletableFuture<LPSubject> handle() {
|
||||||
return this.ref.resolveLp();
|
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
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public LPSubjectReference asSubjectReference() {
|
public LPSubjectReference asSubjectReference() {
|
||||||
@ -165,7 +171,7 @@ public final class SubjectProxy implements Subject, ProxiedSubject {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public Set<Context> getActiveContexts() {
|
public Set<Context> getActiveContexts() {
|
||||||
return CompatibilityUtil.convertContexts(this.contextsCache.getContextSet());
|
return CompatibilityUtil.convertContexts(getContextsCache().getContextSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user