mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 11:38:40 +01:00
Improve memory footprint in low throughput caches
This commit is contained in:
parent
829eacb0fb
commit
8a692200d5
@ -58,6 +58,7 @@ import me.lucko.luckperms.common.managers.impl.GenericUserManager;
|
|||||||
import me.lucko.luckperms.common.messaging.RedisMessaging;
|
import me.lucko.luckperms.common.messaging.RedisMessaging;
|
||||||
import me.lucko.luckperms.common.storage.Storage;
|
import me.lucko.luckperms.common.storage.Storage;
|
||||||
import me.lucko.luckperms.common.storage.StorageFactory;
|
import me.lucko.luckperms.common.storage.StorageFactory;
|
||||||
|
import me.lucko.luckperms.common.tasks.CacheHousekeepingTask;
|
||||||
import me.lucko.luckperms.common.tasks.ExpireTemporaryTask;
|
import me.lucko.luckperms.common.tasks.ExpireTemporaryTask;
|
||||||
import me.lucko.luckperms.common.tasks.UpdateTask;
|
import me.lucko.luckperms.common.tasks.UpdateTask;
|
||||||
import me.lucko.luckperms.common.utils.BufferedRequest;
|
import me.lucko.luckperms.common.utils.BufferedRequest;
|
||||||
@ -252,6 +253,7 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
|
|||||||
|
|
||||||
// register tasks
|
// register tasks
|
||||||
getServer().getScheduler().runTaskTimerAsynchronously(this, new ExpireTemporaryTask(this), 60L, 60L);
|
getServer().getScheduler().runTaskTimerAsynchronously(this, new ExpireTemporaryTask(this), 60L, 60L);
|
||||||
|
getServer().getScheduler().runTaskTimerAsynchronously(this, new CacheHousekeepingTask(this), 2400L, 2400L);
|
||||||
|
|
||||||
// register permissions
|
// register permissions
|
||||||
registerPermissions(getConfiguration().isCommandsAllowOp() ? PermissionDefault.OP : PermissionDefault.FALSE);
|
registerPermissions(getConfiguration().isCommandsAllowOp() ? PermissionDefault.OP : PermissionDefault.FALSE);
|
||||||
|
@ -51,6 +51,7 @@ import me.lucko.luckperms.common.managers.impl.GenericUserManager;
|
|||||||
import me.lucko.luckperms.common.messaging.RedisMessaging;
|
import me.lucko.luckperms.common.messaging.RedisMessaging;
|
||||||
import me.lucko.luckperms.common.storage.Storage;
|
import me.lucko.luckperms.common.storage.Storage;
|
||||||
import me.lucko.luckperms.common.storage.StorageFactory;
|
import me.lucko.luckperms.common.storage.StorageFactory;
|
||||||
|
import me.lucko.luckperms.common.tasks.CacheHousekeepingTask;
|
||||||
import me.lucko.luckperms.common.tasks.ExpireTemporaryTask;
|
import me.lucko.luckperms.common.tasks.ExpireTemporaryTask;
|
||||||
import me.lucko.luckperms.common.tasks.UpdateTask;
|
import me.lucko.luckperms.common.tasks.UpdateTask;
|
||||||
import me.lucko.luckperms.common.utils.BufferedRequest;
|
import me.lucko.luckperms.common.utils.BufferedRequest;
|
||||||
@ -187,6 +188,7 @@ public class LPBungeePlugin extends Plugin implements LuckPermsPlugin {
|
|||||||
|
|
||||||
// register tasks
|
// register tasks
|
||||||
getProxy().getScheduler().schedule(this, new ExpireTemporaryTask(this), 3L, 3L, TimeUnit.SECONDS);
|
getProxy().getScheduler().schedule(this, new ExpireTemporaryTask(this), 3L, 3L, TimeUnit.SECONDS);
|
||||||
|
getProxy().getScheduler().schedule(this, new CacheHousekeepingTask(this), 2L, 2L, TimeUnit.MINUTES);
|
||||||
|
|
||||||
getLog().info("Successfully loaded.");
|
getLog().info("Successfully loaded.");
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@ import me.lucko.luckperms.common.core.model.User;
|
|||||||
import me.lucko.luckperms.common.utils.ExtractedContexts;
|
import me.lucko.luckperms.common.utils.ExtractedContexts;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds an easily accessible cache of a user's data in a number of contexts
|
* Holds an easily accessible cache of a user's data in a number of contexts
|
||||||
@ -59,6 +60,7 @@ public class UserCache implements UserData {
|
|||||||
private final CalculatorFactory calculatorFactory;
|
private final CalculatorFactory calculatorFactory;
|
||||||
|
|
||||||
private final LoadingCache<Contexts, PermissionCache> permission = CacheBuilder.newBuilder()
|
private final LoadingCache<Contexts, PermissionCache> permission = CacheBuilder.newBuilder()
|
||||||
|
.expireAfterAccess(10, TimeUnit.MINUTES)
|
||||||
.build(new CacheLoader<Contexts, PermissionCache>() {
|
.build(new CacheLoader<Contexts, PermissionCache>() {
|
||||||
@Override
|
@Override
|
||||||
public PermissionCache load(Contexts contexts) {
|
public PermissionCache load(Contexts contexts) {
|
||||||
@ -73,6 +75,7 @@ public class UserCache implements UserData {
|
|||||||
});
|
});
|
||||||
|
|
||||||
private final LoadingCache<Contexts, MetaCache> meta = CacheBuilder.newBuilder()
|
private final LoadingCache<Contexts, MetaCache> meta = CacheBuilder.newBuilder()
|
||||||
|
.expireAfterAccess(10, TimeUnit.MINUTES)
|
||||||
.build(new CacheLoader<Contexts, MetaCache>() {
|
.build(new CacheLoader<Contexts, MetaCache>() {
|
||||||
@Override
|
@Override
|
||||||
public MetaCache load(Contexts contexts) {
|
public MetaCache load(Contexts contexts) {
|
||||||
@ -153,4 +156,9 @@ public class UserCache implements UserData {
|
|||||||
permission.asMap().values().forEach(PermissionData::invalidateCache);
|
permission.asMap().values().forEach(PermissionData::invalidateCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void cleanup() {
|
||||||
|
permission.cleanUp();
|
||||||
|
meta.cleanUp();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -76,6 +76,7 @@ import java.util.Set;
|
|||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.Lock;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -142,6 +143,7 @@ public abstract class PermissionHolder {
|
|||||||
/* External Caches - may depend on the state of other instances. */
|
/* External Caches - may depend on the state of other instances. */
|
||||||
|
|
||||||
private LoadingCache<GetAllNodesHolder, SortedSet<LocalizedNode>> getAllNodesCache = CacheBuilder.newBuilder()
|
private LoadingCache<GetAllNodesHolder, SortedSet<LocalizedNode>> getAllNodesCache = CacheBuilder.newBuilder()
|
||||||
|
.expireAfterAccess(10, TimeUnit.MINUTES)
|
||||||
.build(new CacheLoader<GetAllNodesHolder, SortedSet<LocalizedNode>>() {
|
.build(new CacheLoader<GetAllNodesHolder, SortedSet<LocalizedNode>>() {
|
||||||
@Override
|
@Override
|
||||||
public SortedSet<LocalizedNode> load(GetAllNodesHolder getAllNodesHolder) {
|
public SortedSet<LocalizedNode> load(GetAllNodesHolder getAllNodesHolder) {
|
||||||
@ -149,6 +151,7 @@ public abstract class PermissionHolder {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
private LoadingCache<ExtractedContexts, Set<LocalizedNode>> getAllNodesFilteredCache = CacheBuilder.newBuilder()
|
private LoadingCache<ExtractedContexts, Set<LocalizedNode>> getAllNodesFilteredCache = CacheBuilder.newBuilder()
|
||||||
|
.expireAfterAccess(10, TimeUnit.MINUTES)
|
||||||
.build(new CacheLoader<ExtractedContexts, Set<LocalizedNode>>() {
|
.build(new CacheLoader<ExtractedContexts, Set<LocalizedNode>>() {
|
||||||
@Override
|
@Override
|
||||||
public Set<LocalizedNode> load(ExtractedContexts extractedContexts) throws Exception {
|
public Set<LocalizedNode> load(ExtractedContexts extractedContexts) throws Exception {
|
||||||
@ -156,6 +159,7 @@ public abstract class PermissionHolder {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
private LoadingCache<ExportNodesHolder, Map<String, Boolean>> exportNodesCache = CacheBuilder.newBuilder()
|
private LoadingCache<ExportNodesHolder, Map<String, Boolean>> exportNodesCache = CacheBuilder.newBuilder()
|
||||||
|
.expireAfterAccess(10, TimeUnit.MINUTES)
|
||||||
.build(new CacheLoader<ExportNodesHolder, Map<String, Boolean>>() {
|
.build(new CacheLoader<ExportNodesHolder, Map<String, Boolean>>() {
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Boolean> load(ExportNodesHolder exportNodesHolder) throws Exception {
|
public Map<String, Boolean> load(ExportNodesHolder exportNodesHolder) throws Exception {
|
||||||
@ -167,6 +171,12 @@ public abstract class PermissionHolder {
|
|||||||
|
|
||||||
/* Caching apply methods. Are just called by the caching instances to gather data about the instance. */
|
/* Caching apply methods. Are just called by the caching instances to gather data about the instance. */
|
||||||
|
|
||||||
|
protected void forceCleanup() {
|
||||||
|
getAllNodesCache.cleanUp();
|
||||||
|
getAllNodesFilteredCache.cleanUp();
|
||||||
|
exportNodesCache.cleanUp();
|
||||||
|
}
|
||||||
|
|
||||||
private void invalidateCache(boolean enduring) {
|
private void invalidateCache(boolean enduring) {
|
||||||
if (enduring) {
|
if (enduring) {
|
||||||
enduringCache.invalidate();
|
enduringCache.invalidate();
|
||||||
|
@ -149,4 +149,12 @@ public class User extends PermissionHolder implements Identifiable<UserIdentifie
|
|||||||
super.clearNodes();
|
super.clearNodes();
|
||||||
getPlugin().getUserManager().giveDefaultIfNeeded(this, false);
|
getPlugin().getUserManager().giveDefaultIfNeeded(this, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void cleanup() {
|
||||||
|
UserCache cache = userData;
|
||||||
|
if (cache != null) {
|
||||||
|
cache.cleanup();
|
||||||
|
}
|
||||||
|
forceCleanup();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.common.tasks;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.common.LuckPermsPlugin;
|
||||||
|
import me.lucko.luckperms.common.core.model.User;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class CacheHousekeepingTask implements Runnable {
|
||||||
|
private final LuckPermsPlugin plugin;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for (User user : plugin.getUserManager().getAll().values()) {
|
||||||
|
user.cleanup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -48,6 +48,7 @@ import me.lucko.luckperms.common.managers.impl.GenericTrackManager;
|
|||||||
import me.lucko.luckperms.common.messaging.RedisMessaging;
|
import me.lucko.luckperms.common.messaging.RedisMessaging;
|
||||||
import me.lucko.luckperms.common.storage.Storage;
|
import me.lucko.luckperms.common.storage.Storage;
|
||||||
import me.lucko.luckperms.common.storage.StorageFactory;
|
import me.lucko.luckperms.common.storage.StorageFactory;
|
||||||
|
import me.lucko.luckperms.common.tasks.CacheHousekeepingTask;
|
||||||
import me.lucko.luckperms.common.tasks.ExpireTemporaryTask;
|
import me.lucko.luckperms.common.tasks.ExpireTemporaryTask;
|
||||||
import me.lucko.luckperms.common.tasks.UpdateTask;
|
import me.lucko.luckperms.common.tasks.UpdateTask;
|
||||||
import me.lucko.luckperms.common.utils.BufferedRequest;
|
import me.lucko.luckperms.common.utils.BufferedRequest;
|
||||||
@ -60,6 +61,7 @@ import me.lucko.luckperms.sponge.contexts.WorldCalculator;
|
|||||||
import me.lucko.luckperms.sponge.managers.SpongeGroupManager;
|
import me.lucko.luckperms.sponge.managers.SpongeGroupManager;
|
||||||
import me.lucko.luckperms.sponge.managers.SpongeUserManager;
|
import me.lucko.luckperms.sponge.managers.SpongeUserManager;
|
||||||
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
import me.lucko.luckperms.sponge.service.LuckPermsService;
|
||||||
|
import me.lucko.luckperms.sponge.service.ServiceCacheHousekeepingTask;
|
||||||
import me.lucko.luckperms.sponge.timings.LPTimings;
|
import me.lucko.luckperms.sponge.timings.LPTimings;
|
||||||
import me.lucko.luckperms.sponge.utils.VersionData;
|
import me.lucko.luckperms.sponge.utils.VersionData;
|
||||||
|
|
||||||
@ -250,6 +252,9 @@ public class LPSpongePlugin implements LuckPermsPlugin {
|
|||||||
|
|
||||||
// register tasks
|
// register tasks
|
||||||
scheduler.createTaskBuilder().async().intervalTicks(60L).execute(new ExpireTemporaryTask(this)).submit(this);
|
scheduler.createTaskBuilder().async().intervalTicks(60L).execute(new ExpireTemporaryTask(this)).submit(this);
|
||||||
|
scheduler.createTaskBuilder().async().intervalTicks(2400L).execute(new CacheHousekeepingTask(this)).submit(this);
|
||||||
|
scheduler.createTaskBuilder().async().intervalTicks(2400L).execute(new ServiceCacheHousekeepingTask(service)).submit(this);
|
||||||
|
scheduler.createTaskBuilder().async().intervalTicks(2400L).execute(() -> userManager.performCleanup()).submit(this);
|
||||||
|
|
||||||
getLog().info("Successfully loaded.");
|
getLog().info("Successfully loaded.");
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,7 @@ import org.spongepowered.api.service.permission.PermissionService;
|
|||||||
import co.aikar.timings.Timing;
|
import co.aikar.timings.Timing;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@ -83,6 +84,17 @@ public class SpongeUserManager implements UserManager, LPSubjectCollection {
|
|||||||
new SpongeUser(id.getUuid(), id.getUsername(), plugin);
|
new SpongeUser(id.getUuid(), id.getUsername(), plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void performCleanup() {
|
||||||
|
Set<UserIdentifier> set = new HashSet<>();
|
||||||
|
for (Map.Entry<UserIdentifier, SpongeUser> user : objects.asMap().entrySet()) {
|
||||||
|
if (user.getValue().getSpongeData().shouldCleanup()) {
|
||||||
|
set.add(user.getKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
objects.invalidateAll(set);
|
||||||
|
}
|
||||||
|
|
||||||
/* ------------------------------------------
|
/* ------------------------------------------
|
||||||
* Manager methods
|
* Manager methods
|
||||||
* ------------------------------------------ */
|
* ------------------------------------------ */
|
||||||
@ -109,7 +121,6 @@ public class SpongeUserManager implements UserManager, LPSubjectCollection {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unload(User t) {
|
public void unload(User t) {
|
||||||
// TODO override
|
|
||||||
if (t != null) {
|
if (t != null) {
|
||||||
objects.invalidate(t.getId());
|
objects.invalidate(t.getId());
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,7 @@ import co.aikar.timings.Timing;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class SpongeGroup extends Group {
|
public class SpongeGroup extends Group {
|
||||||
@ -77,6 +78,7 @@ public class SpongeGroup extends Group {
|
|||||||
private final LuckPermsSubjectData transientSubjectData;
|
private final LuckPermsSubjectData transientSubjectData;
|
||||||
|
|
||||||
private final LoadingCache<ContextSet, NodeTree> permissionCache = CacheBuilder.newBuilder()
|
private final LoadingCache<ContextSet, NodeTree> permissionCache = CacheBuilder.newBuilder()
|
||||||
|
.expireAfterAccess(10, TimeUnit.MINUTES)
|
||||||
.build(new CacheLoader<ContextSet, NodeTree>() {
|
.build(new CacheLoader<ContextSet, NodeTree>() {
|
||||||
@Override
|
@Override
|
||||||
public NodeTree load(ContextSet contexts) {
|
public NodeTree load(ContextSet contexts) {
|
||||||
@ -90,6 +92,7 @@ public class SpongeGroup extends Group {
|
|||||||
});
|
});
|
||||||
|
|
||||||
private final LoadingCache<ContextSet, Set<SubjectReference>> parentCache = CacheBuilder.newBuilder()
|
private final LoadingCache<ContextSet, Set<SubjectReference>> parentCache = CacheBuilder.newBuilder()
|
||||||
|
.expireAfterWrite(10, TimeUnit.MINUTES)
|
||||||
.build(new CacheLoader<ContextSet, Set<SubjectReference>>() {
|
.build(new CacheLoader<ContextSet, Set<SubjectReference>>() {
|
||||||
@Override
|
@Override
|
||||||
public Set<SubjectReference> load(ContextSet contexts) {
|
public Set<SubjectReference> load(ContextSet contexts) {
|
||||||
@ -120,6 +123,12 @@ public class SpongeGroup extends Group {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void performCleanup() {
|
||||||
|
permissionCache.cleanUp();
|
||||||
|
parentCache.cleanUp();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getIdentifier() {
|
public String getIdentifier() {
|
||||||
return parent.getObjectName();
|
return parent.getObjectName();
|
||||||
|
@ -74,6 +74,8 @@ public class SpongeUser extends User {
|
|||||||
@Getter
|
@Getter
|
||||||
private final LuckPermsSubjectData transientSubjectData;
|
private final LuckPermsSubjectData transientSubjectData;
|
||||||
|
|
||||||
|
private long lastUse = System.currentTimeMillis();
|
||||||
|
|
||||||
private UserSubject(LPSpongePlugin plugin, SpongeUser parent) {
|
private UserSubject(LPSpongePlugin plugin, SpongeUser parent) {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@ -81,6 +83,16 @@ public class SpongeUser extends User {
|
|||||||
this.transientSubjectData = new LuckPermsSubjectData(false, plugin.getService(), parent, this);
|
this.transientSubjectData = new LuckPermsSubjectData(false, plugin.getService(), parent, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void logUsage() {
|
||||||
|
lastUse = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean shouldCleanup() {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
// Expire after 10 minutes of idle
|
||||||
|
return (now - lastUse) > 600000;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean hasData() {
|
private boolean hasData() {
|
||||||
return parent.getUserData() != null;
|
return parent.getUserData() != null;
|
||||||
}
|
}
|
||||||
@ -114,6 +126,7 @@ public class SpongeUser extends User {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Tristate getPermissionValue(ContextSet contexts, String permission) {
|
public Tristate getPermissionValue(ContextSet contexts, String permission) {
|
||||||
|
logUsage();
|
||||||
try (Timing ignored = plugin.getTimings().time(LPTiming.USER_GET_PERMISSION_VALUE)) {
|
try (Timing ignored = plugin.getTimings().time(LPTiming.USER_GET_PERMISSION_VALUE)) {
|
||||||
if (!hasData()) {
|
if (!hasData()) {
|
||||||
return Tristate.UNDEFINED;
|
return Tristate.UNDEFINED;
|
||||||
@ -125,6 +138,7 @@ public class SpongeUser extends User {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isChildOf(ContextSet contexts, SubjectReference parent) {
|
public boolean isChildOf(ContextSet contexts, SubjectReference parent) {
|
||||||
|
logUsage();
|
||||||
try (Timing ignored = plugin.getTimings().time(LPTiming.USER_IS_CHILD_OF)) {
|
try (Timing ignored = plugin.getTimings().time(LPTiming.USER_IS_CHILD_OF)) {
|
||||||
return parent.getCollection().equals(PermissionService.SUBJECTS_GROUP) && getPermissionValue(contexts, "group." + parent.getIdentifier()).asBoolean();
|
return parent.getCollection().equals(PermissionService.SUBJECTS_GROUP) && getPermissionValue(contexts, "group." + parent.getIdentifier()).asBoolean();
|
||||||
}
|
}
|
||||||
@ -132,6 +146,7 @@ public class SpongeUser extends User {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<SubjectReference> getParents(ContextSet contexts) {
|
public Set<SubjectReference> getParents(ContextSet contexts) {
|
||||||
|
logUsage();
|
||||||
try (Timing ignored = plugin.getTimings().time(LPTiming.USER_GET_PARENTS)) {
|
try (Timing ignored = plugin.getTimings().time(LPTiming.USER_GET_PARENTS)) {
|
||||||
ImmutableSet.Builder<SubjectReference> subjects = ImmutableSet.builder();
|
ImmutableSet.Builder<SubjectReference> subjects = ImmutableSet.builder();
|
||||||
|
|
||||||
@ -157,6 +172,7 @@ public class SpongeUser extends User {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> getOption(ContextSet contexts, String s) {
|
public Optional<String> getOption(ContextSet contexts, String s) {
|
||||||
|
logUsage();
|
||||||
try (Timing ignored = plugin.getTimings().time(LPTiming.USER_GET_OPTION)) {
|
try (Timing ignored = plugin.getTimings().time(LPTiming.USER_GET_OPTION)) {
|
||||||
if (hasData()) {
|
if (hasData()) {
|
||||||
MetaData data = parent.getUserData().getMetaData(plugin.getService().calculateContexts(contexts));
|
MetaData data = parent.getUserData().getMetaData(plugin.getService().calculateContexts(contexts));
|
||||||
@ -188,6 +204,7 @@ public class SpongeUser extends User {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ContextSet getActiveContextSet() {
|
public ContextSet getActiveContextSet() {
|
||||||
|
logUsage();
|
||||||
try (Timing ignored = plugin.getTimings().time(LPTiming.USER_GET_ACTIVE_CONTEXTS)) {
|
try (Timing ignored = plugin.getTimings().time(LPTiming.USER_GET_ACTIVE_CONTEXTS)) {
|
||||||
return plugin.getContextManager().getApplicableContext(this);
|
return plugin.getContextManager().getApplicableContext(this);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016 Lucko (Luck) <luck@lucko.me>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package me.lucko.luckperms.sponge.service;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
import me.lucko.luckperms.sponge.service.base.LPSubject;
|
||||||
|
import me.lucko.luckperms.sponge.service.base.LPSubjectCollection;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class ServiceCacheHousekeepingTask implements Runnable {
|
||||||
|
private final LuckPermsService service;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
for (LPSubjectCollection collection : service.getCollections().values()) {
|
||||||
|
for (LPSubject subject : collection.getSubjects()) {
|
||||||
|
subject.performCleanup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -60,6 +60,10 @@ public interface LPSubject extends Subject {
|
|||||||
|
|
||||||
LuckPermsService getService();
|
LuckPermsService getService();
|
||||||
|
|
||||||
|
default void performCleanup() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
default SubjectReference toReference() {
|
default SubjectReference toReference() {
|
||||||
return SubjectReference.of(getParentCollection().getCollection(), getIdentifier());
|
return SubjectReference.of(getParentCollection().getCollection(), getIdentifier());
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,7 @@ import java.util.Objects;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.SortedMap;
|
import java.util.SortedMap;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class CalculatedSubjectData implements LPSubjectData {
|
public class CalculatedSubjectData implements LPSubjectData {
|
||||||
@ -102,6 +103,7 @@ public class CalculatedSubjectData implements LPSubjectData {
|
|||||||
|
|
||||||
private final Map<ContextSet, Map<String, Boolean>> permissions = new ConcurrentHashMap<>();
|
private final Map<ContextSet, Map<String, Boolean>> permissions = new ConcurrentHashMap<>();
|
||||||
private final LoadingCache<ContextSet, CalculatorHolder> permissionCache = CacheBuilder.newBuilder()
|
private final LoadingCache<ContextSet, CalculatorHolder> permissionCache = CacheBuilder.newBuilder()
|
||||||
|
.expireAfterAccess(10, TimeUnit.MINUTES)
|
||||||
.build(new CacheLoader<ContextSet, CalculatorHolder>() {
|
.build(new CacheLoader<ContextSet, CalculatorHolder>() {
|
||||||
@Override
|
@Override
|
||||||
public CalculatorHolder load(ContextSet contexts) {
|
public CalculatorHolder load(ContextSet contexts) {
|
||||||
@ -119,6 +121,10 @@ public class CalculatedSubjectData implements LPSubjectData {
|
|||||||
private final Map<ContextSet, Set<SubjectReference>> parents = new ConcurrentHashMap<>();
|
private final Map<ContextSet, Set<SubjectReference>> parents = new ConcurrentHashMap<>();
|
||||||
private final Map<ContextSet, Map<String, String>> options = new ConcurrentHashMap<>();
|
private final Map<ContextSet, Map<String, String>> options = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public void cleanup() {
|
||||||
|
permissionCache.cleanUp();
|
||||||
|
}
|
||||||
|
|
||||||
public Tristate getPermissionValue(ContextSet contexts, String permission) {
|
public Tristate getPermissionValue(ContextSet contexts, String permission) {
|
||||||
return permissionCache.getUnchecked(contexts).getCalculator().getPermissionValue(permission);
|
return permissionCache.getUnchecked(contexts).getCalculator().getPermissionValue(permission);
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,7 @@ import java.io.IOException;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple persistable Subject implementation
|
* A simple persistable Subject implementation
|
||||||
@ -66,6 +67,7 @@ public class PersistedSubject implements LPSubject {
|
|||||||
private final CalculatedSubjectData transientSubjectData;
|
private final CalculatedSubjectData transientSubjectData;
|
||||||
|
|
||||||
private final LoadingCache<PermissionLookup, Tristate> permissionLookupCache = CacheBuilder.newBuilder()
|
private final LoadingCache<PermissionLookup, Tristate> permissionLookupCache = CacheBuilder.newBuilder()
|
||||||
|
.expireAfterAccess(20, TimeUnit.MINUTES)
|
||||||
.build(new CacheLoader<PermissionLookup, Tristate>() {
|
.build(new CacheLoader<PermissionLookup, Tristate>() {
|
||||||
@Override
|
@Override
|
||||||
public Tristate load(PermissionLookup lookup) {
|
public Tristate load(PermissionLookup lookup) {
|
||||||
@ -73,6 +75,7 @@ public class PersistedSubject implements LPSubject {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
private final LoadingCache<ImmutableContextSet, Set<SubjectReference>> parentLookupCache = CacheBuilder.newBuilder()
|
private final LoadingCache<ImmutableContextSet, Set<SubjectReference>> parentLookupCache = CacheBuilder.newBuilder()
|
||||||
|
.expireAfterAccess(20, TimeUnit.MINUTES)
|
||||||
.build(new CacheLoader<ImmutableContextSet, Set<SubjectReference>>() {
|
.build(new CacheLoader<ImmutableContextSet, Set<SubjectReference>>() {
|
||||||
@Override
|
@Override
|
||||||
public Set<SubjectReference> load(ImmutableContextSet contexts) {
|
public Set<SubjectReference> load(ImmutableContextSet contexts) {
|
||||||
@ -80,6 +83,7 @@ public class PersistedSubject implements LPSubject {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
private final LoadingCache<OptionLookup, Optional<String>> optionLookupCache = CacheBuilder.newBuilder()
|
private final LoadingCache<OptionLookup, Optional<String>> optionLookupCache = CacheBuilder.newBuilder()
|
||||||
|
.expireAfterAccess(20, TimeUnit.MINUTES)
|
||||||
.build(new CacheLoader<OptionLookup, Optional<String>>() {
|
.build(new CacheLoader<OptionLookup, Optional<String>>() {
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> load(OptionLookup lookup) {
|
public Optional<String> load(OptionLookup lookup) {
|
||||||
@ -115,6 +119,15 @@ public class PersistedSubject implements LPSubject {
|
|||||||
service.getLocalOptionCaches().add(optionLookupCache);
|
service.getLocalOptionCaches().add(optionLookupCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void performCleanup() {
|
||||||
|
this.subjectData.cleanup();
|
||||||
|
this.transientSubjectData.cleanup();
|
||||||
|
this.permissionLookupCache.cleanUp();
|
||||||
|
this.parentLookupCache.cleanUp();
|
||||||
|
this.optionLookupCache.cleanUp();
|
||||||
|
}
|
||||||
|
|
||||||
public void loadData(SubjectDataHolder dataHolder) {
|
public void loadData(SubjectDataHolder dataHolder) {
|
||||||
subjectData.setSave(false);
|
subjectData.setSave(false);
|
||||||
dataHolder.copyTo(subjectData);
|
dataHolder.copyTo(subjectData);
|
||||||
|
Loading…
Reference in New Issue
Block a user