Merge "Add getCacheKey() to CurrentUser and its implementations"

This commit is contained in:
Patrick Hiesel
2018-04-18 11:49:33 +00:00
committed by Gerrit Code Review
9 changed files with 43 additions and 1 deletions

View File

@@ -26,6 +26,12 @@ public class AnonymousUser extends CurrentUser {
return new ListGroupMembership(Collections.singleton(SystemGroupBackend.ANONYMOUS_USERS));
}
@Override
public Object getCacheKey() {
// Treat all anonymous users as a single user
return "anonymous";
}
@Override
public String toString() {
return "ANONYMOUS";

View File

@@ -90,6 +90,12 @@ public abstract class CurrentUser {
*/
public abstract GroupMembership getEffectiveGroups();
/**
* Returns a unique identifier for this user that is intended to be used as a cache key. Returned
* object should to implement {@code equals()} and {@code hashCode()} for effective caching.
*/
public abstract Object getCacheKey();
/** Unique name of the user on this server, if one has been assigned. */
public Optional<String> getUserName() {
return Optional.empty();

View File

@@ -382,6 +382,11 @@ public class IdentifiedUser extends CurrentUser {
return effectiveGroups;
}
@Override
public Object getCacheKey() {
return getAccountId();
}
public PersonIdent newRefLogIdent() {
return newRefLogIdent(new Date(), TimeZone.getDefault());
}

View File

@@ -35,6 +35,11 @@ public class InternalUser extends CurrentUser {
return GroupMembership.EMPTY;
}
@Override
public String getCacheKey() {
return "internal";
}
@Override
public boolean isInternalUser() {
return true;

View File

@@ -40,6 +40,11 @@ public class PeerDaemonUser extends CurrentUser {
return GroupMembership.EMPTY;
}
@Override
public Object getCacheKey() {
return getRemoteAddress();
}
public SocketAddress getRemoteAddress() {
return peer;
}

View File

@@ -36,4 +36,9 @@ public final class SingleGroupUser extends CurrentUser {
public GroupMembership getEffectiveGroups() {
return groups;
}
@Override
public Object getCacheKey() {
return groups.getKnownGroups();
}
}

View File

@@ -50,6 +50,11 @@ public class UiActionsTest {
throw new UnsupportedOperationException("not implemented");
}
@Override
public Object getCacheKey() {
return new Object();
}
@Override
public boolean isIdentifiedUser() {
return true;

View File

@@ -1012,6 +1012,11 @@ public class RefControlTest {
return groups;
}
@Override
public Object getCacheKey() {
return new Object();
}
@Override
public Optional<String> getUserName() {
return Optional.ofNullable(username);