From 46dc4e51040bc3a8da3db4e59211da94bc1b8463 Mon Sep 17 00:00:00 2001 From: Luck Date: Sun, 29 Dec 2019 17:54:11 +0000 Subject: [PATCH] Cleanup verbose logging for groups --- .../cacheddata/AbstractCachedDataManager.java | 3 +- .../common/cacheddata/type/MetaCache.java | 51 +++++++++---------- .../calculator/PermissionCalculator.java | 28 +++++----- 3 files changed, 39 insertions(+), 43 deletions(-) diff --git a/common/src/main/java/me/lucko/luckperms/common/cacheddata/AbstractCachedDataManager.java b/common/src/main/java/me/lucko/luckperms/common/cacheddata/AbstractCachedDataManager.java index d357191cc..db37f3d1f 100644 --- a/common/src/main/java/me/lucko/luckperms/common/cacheddata/AbstractCachedDataManager.java +++ b/common/src/main/java/me/lucko/luckperms/common/cacheddata/AbstractCachedDataManager.java @@ -153,7 +153,7 @@ public abstract class AbstractCachedDataManager implements CachedDataManager { if (data == null) { CacheMetadata metadata = getMetadataForQueryOptions(queryOptions); - data = new MetaCache(queryOptions, metadata); + data = new MetaCache(this.plugin, queryOptions, metadata); } MetaAccumulator accumulator = newAccumulator(queryOptions); @@ -266,7 +266,6 @@ public abstract class AbstractCachedDataManager implements CachedDataManager { .expireAfterAccess(2, TimeUnit.MINUTES) .buildAsync(new MetaCacheLoader()); - @Override public @NonNull MetaCache get(@NonNull QueryOptions queryOptions) { Objects.requireNonNull(queryOptions, "queryOptions"); diff --git a/common/src/main/java/me/lucko/luckperms/common/cacheddata/type/MetaCache.java b/common/src/main/java/me/lucko/luckperms/common/cacheddata/type/MetaCache.java index b20da06fc..4b66c03b1 100644 --- a/common/src/main/java/me/lucko/luckperms/common/cacheddata/type/MetaCache.java +++ b/common/src/main/java/me/lucko/luckperms/common/cacheddata/type/MetaCache.java @@ -33,9 +33,10 @@ import com.google.common.collect.Multimaps; import me.lucko.luckperms.common.cacheddata.CacheMetadata; import me.lucko.luckperms.common.metastacking.MetaStack; +import me.lucko.luckperms.common.model.HolderType; import me.lucko.luckperms.common.node.types.Prefix; import me.lucko.luckperms.common.node.types.Suffix; -import me.lucko.luckperms.common.verbose.VerboseHandler; +import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.verbose.event.MetaCheckEvent; import net.luckperms.api.cacheddata.CachedMetaData; @@ -54,16 +55,19 @@ import java.util.SortedMap; */ public class MetaCache implements CachedMetaData { - /** - * The query options this container is holding data for - */ + /** The plugin instance */ + private final LuckPermsPlugin plugin; + + /** The query options this container is holding data for */ private final QueryOptions queryOptions; - /** - * The metadata for this cache - */ + /** The metadata for this cache */ private final CacheMetadata metadata; + /** The object name passed to the verbose handler when checks are made */ + private final String verboseCheckTarget; + + /* The data */ private Map> meta = ImmutableMap.of(); private Map flattenedMeta = ImmutableMap.of(); private SortedMap prefixes = ImmutableSortedMap.of(); @@ -71,9 +75,16 @@ public class MetaCache implements CachedMetaData { private MetaStack prefixStack = null; private MetaStack suffixStack = null; - public MetaCache(QueryOptions queryOptions, CacheMetadata metadata) { + public MetaCache(LuckPermsPlugin plugin, QueryOptions queryOptions, CacheMetadata metadata) { + this.plugin = plugin; this.queryOptions = queryOptions; this.metadata = metadata; + + if (this.metadata.getHolderType() == HolderType.GROUP) { + this.verboseCheckTarget = "group/" + this.metadata.getObjectName(); + } else { + this.verboseCheckTarget = this.metadata.getObjectName(); + } } public void loadMeta(MetaAccumulator meta) { @@ -101,11 +112,7 @@ public class MetaCache implements CachedMetaData { public String getMetaValue(String key, MetaCheckEvent.Origin origin) { Objects.requireNonNull(key, "key"); String value = this.flattenedMeta.get(key); - - // log this meta lookup to the verbose handler - VerboseHandler verboseHandler = MetaCache.this.metadata.getParentContainer().getPlugin().getVerboseHandler(); - verboseHandler.offerMetaCheckEvent(origin, MetaCache.this.metadata.getObjectName(), MetaCache.this.metadata.getQueryOptions(), key, String.valueOf(value)); - + this.plugin.getVerboseHandler().offerMetaCheckEvent(origin, this.verboseCheckTarget, this.metadata.getQueryOptions(), key, String.valueOf(value)); return value; } @@ -117,11 +124,7 @@ public class MetaCache implements CachedMetaData { public String getPrefix(MetaCheckEvent.Origin origin) { MetaStack prefixStack = this.prefixStack; String value = prefixStack == null ? null : prefixStack.toFormattedString(); - - // log this meta lookup to the verbose handler - VerboseHandler verboseHandler = this.metadata.getParentContainer().getPlugin().getVerboseHandler(); - verboseHandler.offerMetaCheckEvent(origin, this.metadata.getObjectName(), this.metadata.getQueryOptions(), Prefix.NODE_KEY, String.valueOf(value)); - + this.plugin.getVerboseHandler().offerMetaCheckEvent(origin, this.verboseCheckTarget, this.metadata.getQueryOptions(), Prefix.NODE_KEY, String.valueOf(value)); return value; } @@ -133,11 +136,7 @@ public class MetaCache implements CachedMetaData { public String getSuffix(MetaCheckEvent.Origin origin) { MetaStack suffixStack = this.suffixStack; String value = suffixStack == null ? null : suffixStack.toFormattedString(); - - // log this meta lookup to the verbose handler - VerboseHandler verboseHandler = this.metadata.getParentContainer().getPlugin().getVerboseHandler(); - verboseHandler.offerMetaCheckEvent(origin, this.metadata.getObjectName(), this.metadata.getQueryOptions(), Suffix.NODE_KEY, String.valueOf(value)); - + this.plugin.getVerboseHandler().offerMetaCheckEvent(origin, this.verboseCheckTarget, this.metadata.getQueryOptions(), Suffix.NODE_KEY, String.valueOf(value)); return value; } @@ -200,11 +199,7 @@ public class MetaCache implements CachedMetaData { String key = (String) k; List values = super.get(key); - - // log this meta lookup to the verbose handler - VerboseHandler verboseHandler = MetaCache.this.metadata.getParentContainer().getPlugin().getVerboseHandler(); - verboseHandler.offerMetaCheckEvent(this.origin, MetaCache.this.metadata.getObjectName(), MetaCache.this.metadata.getQueryOptions(), key, String.valueOf(values)); - + MetaCache.this.plugin.getVerboseHandler().offerMetaCheckEvent(this.origin, MetaCache.this.verboseCheckTarget, MetaCache.this.metadata.getQueryOptions(), key, String.valueOf(values)); return values; } } diff --git a/common/src/main/java/me/lucko/luckperms/common/calculator/PermissionCalculator.java b/common/src/main/java/me/lucko/luckperms/common/calculator/PermissionCalculator.java index 2b0e0e9e4..facd17254 100644 --- a/common/src/main/java/me/lucko/luckperms/common/calculator/PermissionCalculator.java +++ b/common/src/main/java/me/lucko/luckperms/common/calculator/PermissionCalculator.java @@ -31,6 +31,7 @@ import me.lucko.luckperms.common.cache.LoadingMap; import me.lucko.luckperms.common.cacheddata.CacheMetadata; import me.lucko.luckperms.common.calculator.processor.PermissionProcessor; import me.lucko.luckperms.common.calculator.result.TristateResult; +import me.lucko.luckperms.common.model.HolderType; import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.verbose.event.PermissionCheckEvent; @@ -47,30 +48,31 @@ import java.util.function.Function; */ public class PermissionCalculator implements Function { - /** - * The plugin instance - */ + /** The plugin instance */ private final LuckPermsPlugin plugin; - /** - * Info about the nature of this calculator. - */ + /** Info about the nature of this calculator. */ private final CacheMetadata metadata; - /** - * The processors which back this calculator - */ + /** The processors which back this calculator */ private final ImmutableList processors; - /** - * Loading cache for permission checks - */ + /** Loading cache for permission checks */ private final LoadingMap lookupCache = LoadingMap.of(this); + /** The object name passed to the verbose handler when checks are made */ + private final String verboseCheckTarget; + public PermissionCalculator(LuckPermsPlugin plugin, CacheMetadata metadata, ImmutableList processors) { this.plugin = plugin; this.metadata = metadata; this.processors = processors; + + if (this.metadata.getHolderType() == HolderType.GROUP) { + this.verboseCheckTarget = "group/" + this.metadata.getObjectName(); + } else { + this.verboseCheckTarget = this.metadata.getObjectName(); + } } /** @@ -87,7 +89,7 @@ public class PermissionCalculator implements Function { TristateResult result = this.lookupCache.get(permission); // log this permission lookup to the verbose handler - this.plugin.getVerboseHandler().offerPermissionCheckEvent(origin, this.metadata.getObjectName(), this.metadata.getQueryOptions(), permission, result); + this.plugin.getVerboseHandler().offerPermissionCheckEvent(origin, this.verboseCheckTarget, this.metadata.getQueryOptions(), permission, result); // return the result return result;