Remove Common.getAccountCache

Now we only have the server side account cache.

Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2009-08-05 19:04:20 -07:00
parent 4f9cc63269
commit a15ae104be
39 changed files with 494 additions and 666 deletions

View File

@@ -1,95 +0,0 @@
// Copyright (C) 2008 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.client.admin;
import com.google.gerrit.client.data.AccountInfo;
import com.google.gerrit.client.data.AccountInfoCache;
import com.google.gerrit.client.data.AccountInfoCacheFactory;
import com.google.gerrit.client.reviewdb.Account;
import com.google.gerrit.client.reviewdb.AccountGroup;
import com.google.gerrit.client.reviewdb.AccountGroupMember;
import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gwtorm.client.OrmException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class AccountGroupDetail {
protected AccountInfoCache accounts;
protected AccountGroup group;
protected List<AccountGroupMember> members;
protected AccountGroup ownerGroup;
public AccountGroupDetail() {
}
public void load(final ReviewDb db, final AccountInfoCacheFactory acc,
final AccountGroup g) throws OrmException {
group = g;
if (group.getId().equals(group.getOwnerGroupId())) {
ownerGroup = group;
} else {
ownerGroup = db.accountGroups().get(group.getOwnerGroupId());
}
if (!g.isAutomaticMembership()) {
loadMembers(db, acc);
}
}
private void loadMembers(final ReviewDb db, final AccountInfoCacheFactory acc)
throws OrmException {
members = db.accountGroupMembers().byGroup(group.getId()).toList();
for (final AccountGroupMember m : members) {
acc.want(m.getAccountId());
}
accounts = acc.create();
Collections.sort(members, new Comparator<AccountGroupMember>() {
public int compare(final AccountGroupMember o1,
final AccountGroupMember o2) {
final AccountInfo a = accounts.get(o1.getAccountId());
final AccountInfo b = accounts.get(o2.getAccountId());
return n(a).compareTo(n(b));
}
private String n(final AccountInfo a) {
String n = a.getFullName();
if (n != null && n.length() > 0) {
return n;
}
n = a.getPreferredEmail();
if (n != null && n.length() > 0) {
return n;
}
return a.getId().toString();
}
});
}
public void loadOneMember(final ReviewDb db, final Account a,
final AccountGroupMember m) {
final AccountInfoCacheFactory acc = new AccountInfoCacheFactory(db);
acc.put(a);
acc.want(m.getAccountId());
members = new ArrayList<AccountGroupMember>(1);
members.add(m);
accounts = acc.create();
}
}

View File

@@ -70,9 +70,9 @@ public class AccountGroupScreen extends AccountScreen {
protected void onLoad() {
super.onLoad();
Util.GROUP_SVC.groupDetail(groupId,
new ScreenLoadCallback<AccountGroupDetail>(this) {
new ScreenLoadCallback<GroupDetail>(this) {
@Override
protected void preDisplay(final AccountGroupDetail result) {
protected void preDisplay(final GroupDetail result) {
display(result);
}
});
@@ -202,7 +202,7 @@ public class AccountGroupScreen extends AccountScreen {
add(memberPanel);
}
private void display(final AccountGroupDetail result) {
private void display(final GroupDetail result) {
final AccountGroup group = result.group;
setPageTitle(Util.M.group(group.getName()));
groupNameTxt.setText(group.getName());
@@ -229,15 +229,13 @@ public class AccountGroupScreen extends AccountScreen {
addMemberBox.setEnabled(false);
Util.GROUP_SVC.addGroupMember(groupId, nameEmail,
new GerritCallback<AccountGroupDetail>() {
public void onSuccess(final AccountGroupDetail result) {
new GerritCallback<GroupDetail>() {
public void onSuccess(final GroupDetail result) {
addMemberBox.setEnabled(true);
addMemberBox.setText("");
if (result.accounts != null && result.members != null) {
accounts.merge(result.accounts);
for (final AccountGroupMember m : result.members) {
members.insertMember(m);
}
members.display(result.members);
}
}

View File

@@ -33,7 +33,7 @@ public interface GroupAdminService extends RemoteJsonService {
@SignInRequired
void groupDetail(AccountGroup.Id groupId,
AsyncCallback<AccountGroupDetail> callback);
AsyncCallback<GroupDetail> callback);
@SignInRequired
void changeGroupDescription(AccountGroup.Id groupId, String description,
@@ -49,7 +49,7 @@ public interface GroupAdminService extends RemoteJsonService {
@SignInRequired
void addGroupMember(AccountGroup.Id groupId, String nameOrEmail,
AsyncCallback<AccountGroupDetail> callback);
AsyncCallback<GroupDetail> callback);
@SignInRequired
void deleteGroupMembers(AccountGroup.Id groupId,

View File

@@ -0,0 +1,47 @@
// Copyright (C) 2008 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.client.admin;
import com.google.gerrit.client.data.AccountInfoCache;
import com.google.gerrit.client.reviewdb.AccountGroup;
import com.google.gerrit.client.reviewdb.AccountGroupMember;
import java.util.List;
public class GroupDetail {
protected AccountInfoCache accounts;
protected AccountGroup group;
protected List<AccountGroupMember> members;
protected AccountGroup ownerGroup;
public GroupDetail() {
}
public void setAccounts(AccountInfoCache c) {
accounts = c;
}
public void setGroup(AccountGroup g) {
group = g;
}
public void setMembers(List<AccountGroupMember> m) {
members = m;
}
public void setOwnerGroup(AccountGroup g) {
ownerGroup = g;
}
}

View File

@@ -1,167 +0,0 @@
// Copyright (C) 2008 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.client.data;
import com.google.gerrit.client.reviewdb.Account;
import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.SchemaFactory;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
/** Cache of account information. */
@SuppressWarnings("serial")
public class AccountCache {
private final LinkedHashMap<Account.Id, Account> byId =
new LinkedHashMap<Account.Id, Account>(16, 0.75f, true) {
@Override
protected boolean removeEldestEntry(
final Map.Entry<Account.Id, Account> eldest) {
return 4096 <= size();
}
};
private final SchemaFactory<ReviewDb> schema;
public AccountCache(SchemaFactory<ReviewDb> s) {
schema = s;
}
/**
* Invalidate all cached information about a single user account.
*
* @param accountId the account to invalidate from the cache.
*/
public void invalidate(final Account.Id accountId) {
synchronized (byId) {
byId.remove(accountId);
}
}
/**
* Get a single account.
*
* @param accountId the account to obtain.
* @return the cached account entity; null if the account is not in the
* database anymore.
*/
public Account get(final Account.Id accountId) {
return get(accountId, null);
}
/**
* Get a single account.
*
* @param accountId the account to obtain.
* @param qd optional connection to reuse (if not null) when doing a lookup.
* @return the cached account entity; null if the account is not in the
* database anymore.
*/
public Account get(final Account.Id accountId, final ReviewDb qd) {
if (accountId == null) {
return null;
}
Account m;
synchronized (byId) {
m = byId.get(accountId);
}
if (m != null) {
return m;
}
try {
final ReviewDb db = qd != null ? qd : schema.open();
try {
m = db.accounts().get(accountId);
} finally {
if (qd == null) {
db.close();
}
}
} catch (OrmException e) {
m = null;
}
if (m != null) {
synchronized (byId) {
byId.put(m.getId(), m);
}
}
return m;
}
/**
* Lookup multiple account records.
*
* @param fetch set of all accounts to obtain.
* @param qd optional query handle to use if the account data is not in cache.
* @return records which match; if an account listed in <code>fetch</code> is
* not found it will not be returned.
*/
public Collection<Account> get(final Set<Account.Id> fetch, final ReviewDb qd) {
final Set<Account.Id> toget = new HashSet<Account.Id>(fetch);
final Collection<Account> r = new ArrayList<Account>(toget.size());
synchronized (byId) {
for (final Iterator<Account.Id> i = toget.iterator(); i.hasNext();) {
final Account m = byId.get(i.next());
if (m != null) {
r.add(m);
i.remove();
}
}
}
if (!toget.isEmpty()) {
List<Account> found;
try {
final ReviewDb db = qd != null ? qd : schema.open();
try {
found = qd.accounts().get(toget).toList();
} finally {
if (qd == null) {
db.close();
}
}
} catch (OrmException e) {
found = Collections.emptyList();
}
if (!found.isEmpty()) {
synchronized (byId) {
for (final Account a : found) {
byId.put(a.getId(), a);
}
}
r.addAll(found);
}
}
return r;
}
/** Force the entire cache to flush from memory and recompute. */
public void flush() {
synchronized (byId) {
byId.clear();
}
}
}

View File

@@ -38,7 +38,7 @@ public class AccountInfoCache {
protected AccountInfoCache() {
}
AccountInfoCache(final Iterable<AccountInfo> list) {
public AccountInfoCache(final Iterable<AccountInfo> list) {
accounts = new HashMap<Account.Id, AccountInfo>();
for (final AccountInfo ai : list) {
accounts.put(ai.getId(), ai);
@@ -54,7 +54,7 @@ public class AccountInfoCache {
* <li>a valid info block, if <code>id</code> was loaded.</li>
* <li>an anonymous info block, if <code>id</code> was not loaded.</li>
* </ul>
*
*
* @param id the id desired.
* @return info block for the account.
*/

View File

@@ -1,112 +0,0 @@
// Copyright (C) 2008 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.client.data;
import com.google.gerrit.client.reviewdb.Account;
import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.client.rpc.Common;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
/** Efficiently builds a {@link AccountInfoCache}. */
public class AccountInfoCacheFactory {
private final ReviewDb db;
private final HashMap<Account.Id, Account> cache;
private final HashSet<Account.Id> toFetch;
public AccountInfoCacheFactory(final ReviewDb schema) {
db = schema;
cache = new HashMap<Account.Id, Account>();
toFetch = new HashSet<Account.Id>();
}
/**
* Indicate an account will be needed later on.
* <p>
* This method permits batch fetching from the data store by building a list
* of Account.Ids which need to be obtained during the next {@link #fetch}.
*
* @param id identity that will be needed in the future; may be null.
*/
public void want(final Account.Id id) {
if (id != null && !cache.containsKey(id)) {
toFetch.add(id);
}
}
/** Indicate one or more accounts will be needed later on. */
public void want(final Collection<Account.Id> ids) {
for (final Account.Id id : ids) {
want(id);
}
}
/** Fetch all accounts previously queued by {@link #want(Account.Id)} */
public void fetch() {
if (!toFetch.isEmpty()) {
for (final Account a : Common.getAccountCache().get(toFetch, db)) {
cache.put(a.getId(), a);
}
toFetch.clear();
}
}
/** Load one account entity, reusing a cached instance if already loaded. */
public Account get(final Account.Id id) {
if (id == null) {
return null;
}
Account a = cache.get(id);
if (a == null) {
if (toFetch.isEmpty()) {
a = Common.getAccountCache().get(id, db);
if (a != null) {
cache.put(id, a);
}
} else {
toFetch.add(id);
fetch();
a = cache.get(id);
}
}
return a;
}
/** Remember one account that was previously loaded. */
public void put(final Account a) {
toFetch.remove(a.getId());
cache.put(a.getId(), a);
}
/**
* Create an AccountInfoCache with the currently loaded Account entities.
* <p>
* Implicitly invokes {@link #fetch()} prior to creating the cache, ensuring
* any previously enqueued entities will be included in the result.
* */
public AccountInfoCache create() {
fetch();
final List<AccountInfo> r = new ArrayList<AccountInfo>(cache.size());
for (final Account a : cache.values()) {
r.add(new AccountInfo(a));
}
return new AccountInfoCache(r);
}
}

View File

@@ -33,7 +33,7 @@ public class ChangeInfo {
protected ChangeInfo() {
}
public ChangeInfo(final Change c, final AccountInfoCacheFactory acc) {
public ChangeInfo(final Change c) {
id = c.getId();
owner = c.getOwner();
subject = c.getSubject();
@@ -42,8 +42,6 @@ public class ChangeInfo {
branch = c.getDest().getShortName();
lastUpdatedOn = c.getLastUpdatedOn();
sortKey = c.getSortKey();
acc.want(owner);
}
public Change.Id getId() {

View File

@@ -14,14 +14,10 @@
package com.google.gerrit.client.reviewdb;
import com.google.gerrit.client.rpc.Common;
import com.google.gwtorm.client.Column;
import com.google.gwtorm.client.IntKey;
import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.ResultSet;
import java.sql.Timestamp;
import java.util.List;
/**
* Information about a single user.
@@ -37,79 +33,28 @@ import java.util.List;
* predefined {@link ContributorAgreement}. Multiple records indicate
* potentially multiple agreements, especially if agreements must be retired and
* replaced with new agreements.</li>
*
*
* <li>{@link AccountExternalId}: OpenID identities and email addresses known to
* be registered to this user. Multiple records can exist when the user has more
* than one public identity, such as a work and a personal email address.</li>
*
*
* <li>{@link AccountGroupMember}: membership of the user in a specific human
* managed {@link AccountGroup}. Multiple records can exist when the user is a
* member of more than one group.</li>
*
*
* <li>{@link AccountProjectWatch}: user's email settings related to a specific
* {@link Project}. One record per project the user is interested in tracking.</li>
*
*
* <li>{@link AccountSshKey}: user's public SSH keys, for authentication through
* the internal SSH daemon. One record per SSH key uploaded by the user, keys
* are checked in random order until a match is found.</li>
*
*
* <li>{@link StarredChange}: user has starred the change, tracking
* notifications of updates on that change, or just book-marking it for faster
* future reference. One record per starred change.</li>
* </ul>
*/
public final class Account {
/**
* Locate exactly one account matching the name or name/email string.
*
* @param db open database handle to use for the query.
* @param nameOrEmail a string of the format
* "Full Name &lt;email@example&gt;", or just the email address
* ("email@example"), or a full name, or an account id.
* @return the single account that matches; null if no account matches or
* there are multiple candidates.
*/
public static Account find(final ReviewDb db, final String nameOrEmail)
throws OrmException {
if (nameOrEmail.matches("^[1-9][0-9]*$")) {
return Common.getAccountCache().get(Account.Id.parse(nameOrEmail));
}
final int lt = nameOrEmail.indexOf('<');
final int gt = nameOrEmail.indexOf('>');
if (lt >= 0 && gt > lt && nameOrEmail.contains("@")) {
return findByEmail(db, nameOrEmail.substring(lt + 1, gt));
}
if (nameOrEmail.contains("@")) {
return findByEmail(db, nameOrEmail);
}
return oneAccount(db.accounts().byFullName(nameOrEmail));
}
private static Account findByEmail(final ReviewDb db, final String email)
throws OrmException {
Account a = oneAccount(db.accounts().byPreferredEmail(email));
if (a == null) {
a = oneAccountExternalId(db.accountExternalIds().byEmailAddress(email));
}
return a;
}
private static Account oneAccount(ResultSet<Account> rs) {
final List<Account> r = rs.toList();
return r.size() == 1 ? r.get(0) : null;
}
private static Account oneAccountExternalId(ResultSet<AccountExternalId> rs) {
final List<AccountExternalId> r = rs.toList();
if (r.size() == 1) {
return Common.getAccountCache().get(r.get(0).getAccountId());
}
return null;
}
/** Key local to Gerrit to identify a user. */
public static class Id extends IntKey<com.google.gwtorm.client.Key<?>> {
private static final long serialVersionUID = 1L;
@@ -178,7 +123,7 @@ public final class Account {
/**
* Create a new account.
*
*
* @param newId unique id, see {@link ReviewDb#nextAccountId()}.
*/
public Account(final Account.Id newId) {

View File

@@ -14,12 +14,10 @@
package com.google.gerrit.client.rpc;
import com.google.gerrit.client.data.AccountCache;
import com.google.gerrit.client.data.GerritConfig;
public class Common {
private static GerritConfig config;
private static AccountCache accountCache;
/** Get the public configuration data used by this Gerrit instance. */
public static GerritConfig getGerritConfig() {
@@ -29,17 +27,4 @@ public class Common {
public static void setGerritConfig(final GerritConfig imp) {
config = imp;
}
/**
* Get the active AccountCache instance.
* <p>
* <b>Note: this is likely only available on the server side.</b>
*/
public static AccountCache getAccountCache() {
return accountCache;
}
public static void setAccountCache(final AccountCache imp) {
accountCache = imp;
}
}

View File

@@ -25,7 +25,6 @@ import com.google.gerrit.client.reviewdb.ChangeMessage;
import com.google.gerrit.client.reviewdb.PatchSet;
import com.google.gerrit.client.reviewdb.Project;
import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.client.rpc.Common;
import com.google.gerrit.server.ChangeUtil;
import com.google.gerrit.server.GerritServer;
import com.google.gerrit.server.IdentifiedUser;
@@ -80,7 +79,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
/**
* Merges changes in submission order into a single branch.
@@ -535,7 +533,7 @@ public class MergeOp {
private void setRefLogIdent(final ChangeApproval submitAudit) {
if (submitAudit != null) {
branchUpdate.setRefLogIdent(identifiedUserFactory.create(
submitAudit.getAccountId()).toPersonIdent());
submitAudit.getAccountId()).newPersonIdent());
}
}
@@ -629,12 +627,8 @@ public class MergeOp {
continue;
}
final Account acc = Common.getAccountCache().get(a.getAccountId());
if (acc == null) {
// No record of user, WTF?
continue;
}
final Account acc =
identifiedUserFactory.create(a.getAccountId()).getAccount();
final StringBuilder identbuf = new StringBuilder();
if (acc.getFullName() != null && acc.getFullName().length() > 0) {
if (identbuf.length() > 0) {
@@ -724,24 +718,8 @@ public class MergeOp {
if (audit == null) {
return null;
}
final Account a = Common.getAccountCache().get(audit.getAccountId());
if (a == null) {
return null;
}
String name = a.getFullName();
if (name == null || name.length() == 0) {
name = "Anonymous Coward";
}
String email = a.getPreferredEmail();
if (email == null || email.length() == 0) {
email = "account-" + a.getId().get() + "@localhost";
}
final TimeZone tz = myIdent.getTimeZone();
return new PersonIdent(name, email, audit.getGranted(), tz);
return identifiedUserFactory.create(audit.getAccountId()).newPersonIdent(
audit.getGranted(), myIdent.getTimeZone());
}
private void updateBranch() throws MergeException {

View File

@@ -14,14 +14,10 @@
package com.google.gerrit.server;
import com.google.gerrit.client.data.AccountCache;
import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.client.reviewdb.SystemConfig;
import com.google.gerrit.client.rpc.Common;
import com.google.gerrit.server.config.AuthConfig;
import com.google.gerrit.server.config.GerritServerConfig;
import com.google.gerrit.server.config.SitePath;
import com.google.gwtorm.jdbc.Database;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -39,16 +35,13 @@ import java.io.IOException;
/** Global server-side state for Gerrit. */
@Singleton
public class GerritServer {
private final Database<ReviewDb> db;
private final File sitePath;
private final Config gerritConfigFile;
private final File basepath;
@Inject
GerritServer(final Database<ReviewDb> database, final SystemConfig sConfig,
@SitePath final File path, @GerritServerConfig final Config cfg,
final AuthConfig authConfig) {
db = database;
GerritServer(final SystemConfig sConfig, @SitePath final File path,
@GerritServerConfig final Config cfg, final AuthConfig authConfig) {
sitePath = path;
gerritConfigFile = cfg;
@@ -62,8 +55,6 @@ public class GerritServer {
} else {
basepath = null;
}
Common.setAccountCache(new AccountCache(db));
}
private Config getGerritConfig() {

View File

@@ -20,7 +20,7 @@ import com.google.gerrit.client.reviewdb.Change;
import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.client.reviewdb.StarredChange;
import com.google.gerrit.client.reviewdb.SystemConfig;
import com.google.gerrit.server.account.AccountCache2;
import com.google.gerrit.server.account.AccountCache;
import com.google.gerrit.server.account.AccountState;
import com.google.gerrit.server.config.Nullable;
import com.google.gwtorm.client.OrmException;
@@ -38,8 +38,10 @@ import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.TimeZone;
/** An authenticated user. */
public class IdentifiedUser extends CurrentUser {
@@ -47,11 +49,11 @@ public class IdentifiedUser extends CurrentUser {
@Singleton
public static class GenericFactory {
private final SystemConfig systemConfig;
private final AccountCache2 accountCache;
private final AccountCache accountCache;
@Inject
GenericFactory(final SystemConfig systemConfig,
final AccountCache2 accountCache) {
final AccountCache accountCache) {
this.systemConfig = systemConfig;
this.accountCache = accountCache;
}
@@ -70,13 +72,13 @@ public class IdentifiedUser extends CurrentUser {
@Singleton
public static class RequestFactory {
private final SystemConfig systemConfig;
private final AccountCache2 accountCache;
private final AccountCache accountCache;
private final Provider<SocketAddress> remotePeerProvider;
private final Provider<ReviewDb> dbProvider;
@Inject
RequestFactory(final SystemConfig systemConfig,
final AccountCache2 accountCache,
final AccountCache accountCache,
final @RemotePeer Provider<SocketAddress> remotePeerProvider,
final Provider<ReviewDb> dbProvider) {
this.systemConfig = systemConfig;
@@ -94,7 +96,7 @@ public class IdentifiedUser extends CurrentUser {
private static final Logger log =
LoggerFactory.getLogger(IdentifiedUser.class);
private final AccountCache2 accountCache;
private final AccountCache accountCache;
@Nullable
private final Provider<SocketAddress> remotePeerProvider;
@Nullable
@@ -105,7 +107,7 @@ public class IdentifiedUser extends CurrentUser {
private Set<Change.Id> starredChanges;
private IdentifiedUser(final SystemConfig systemConfig,
final AccountCache2 accountCache,
final AccountCache accountCache,
@Nullable final Provider<SocketAddress> remotePeerProvider,
@Nullable final Provider<ReviewDb> dbProvider, final Account.Id id) {
super(systemConfig);
@@ -158,7 +160,11 @@ public class IdentifiedUser extends CurrentUser {
return starredChanges;
}
public PersonIdent toPersonIdent() {
public PersonIdent newPersonIdent() {
return newPersonIdent(new Date(), TimeZone.getDefault());
}
public PersonIdent newPersonIdent(final Date when, final TimeZone tz) {
final Account ua = getAccount();
String name = ua.getFullName();
if (name == null) {
@@ -192,7 +198,7 @@ public class IdentifiedUser extends CurrentUser {
host = "unknown";
}
return new PersonIdent(name, user + "@" + host);
return new PersonIdent(name, user + "@" + host, when, tz);
}
@Override

View File

@@ -43,9 +43,9 @@ import java.util.Set;
/** Caches important (but small) account state to avoid database hits. */
@Singleton
public class AccountCache2 {
public class AccountCache {
private static final Logger log =
LoggerFactory.getLogger(AccountCache2.class);
LoggerFactory.getLogger(AccountCache.class);
private final SchemaFactory<ReviewDb> schema;
private final AuthConfig authConfig;
@@ -55,7 +55,7 @@ public class AccountCache2 {
private final Set<AccountGroup.Id> anonymous;
@Inject
AccountCache2(final SchemaFactory<ReviewDb> sf, final SystemConfig cfg,
AccountCache(final SchemaFactory<ReviewDb> sf, final SystemConfig cfg,
final AuthConfig ac, final CacheManager mgr) {
schema = sf;
authConfig = ac;
@@ -83,7 +83,7 @@ public class AccountCache2 {
if (account == null) {
// Account no longer exists? They are anonymous.
//
return null;
return missing(who);
}
final List<AccountExternalId> ids =

View File

@@ -0,0 +1,75 @@
// Copyright (C) 2009 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.account;
import com.google.gerrit.client.data.AccountInfo;
import com.google.gerrit.client.data.AccountInfoCache;
import com.google.gerrit.client.reviewdb.Account;
import com.google.inject.Inject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** Efficiently builds an {@link AccountInfoCache}. */
public class AccountInfoCacheFactory {
public interface Factory {
AccountInfoCacheFactory create();
}
private final AccountCache accountCache;
private final Map<Account.Id, Account> out;
@Inject
AccountInfoCacheFactory(final AccountCache accountCache) {
this.accountCache = accountCache;
this.out = new HashMap<Account.Id, Account>();
}
/**
* Indicate an account will be needed later on.
*
* @param id identity that will be needed in the future; may be null.
*/
public void want(final Account.Id id) {
if (id != null && !out.containsKey(id)) {
out.put(id, accountCache.get(id).getAccount());
}
}
/** Indicate one or more accounts will be needed later on. */
public void want(final Iterable<Account.Id> ids) {
for (final Account.Id id : ids) {
want(id);
}
}
public Account get(final Account.Id id) {
want(id);
return out.get(id);
}
/**
* Create an AccountInfoCache with the currently loaded Account entities.
* */
public AccountInfoCache create() {
final List<AccountInfo> r = new ArrayList<AccountInfo>(out.size());
for (final Account a : out.values()) {
r.add(new AccountInfo(a));
}
return new AccountInfoCache(r);
}
}

View File

@@ -0,0 +1,86 @@
// Copyright (C) 2009 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.account;
import com.google.gerrit.client.reviewdb.Account;
import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gwtorm.client.OrmException;
import com.google.gwtorm.client.ResultSet;
import com.google.gwtorm.client.SchemaFactory;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.util.List;
import java.util.Set;
@Singleton
public class AccountResolver {
private final AccountByEmailCache byEmail;
private final AccountCache byId;
private final SchemaFactory<ReviewDb> schema;
@Inject
AccountResolver(final AccountByEmailCache byEmail, final AccountCache byId,
final SchemaFactory<ReviewDb> schema) {
this.byEmail = byEmail;
this.byId = byId;
this.schema = schema;
}
/**
* Locate exactly one account matching the name or name/email string.
*
* @param nameOrEmail a string of the format
* "Full Name &lt;email@example&gt;", or just the email address
* ("email@example"), or a full name, or an account id.
* @return the single account that matches; null if no account matches or
* there are multiple candidates.
*/
public Account find(final String nameOrEmail) throws OrmException {
if (nameOrEmail.matches("^[1-9][0-9]*$")) {
return byId.get(Account.Id.parse(nameOrEmail)).getAccount();
}
final int lt = nameOrEmail.indexOf('<');
final int gt = nameOrEmail.indexOf('>');
if (lt >= 0 && gt > lt && nameOrEmail.contains("@")) {
return findByEmail(nameOrEmail.substring(lt + 1, gt));
}
if (nameOrEmail.contains("@")) {
return findByEmail(nameOrEmail);
}
final ReviewDb db = schema.open();
try {
return oneAccount(db.accounts().byFullName(nameOrEmail));
} finally {
db.close();
}
}
private Account findByEmail(final String email) {
final Set<Account.Id> candidates = byEmail.get(email);
if (1 == candidates.size()) {
return byId.get(candidates.iterator().next()).getAccount();
}
return null;
}
private static Account oneAccount(final ResultSet<Account> rs) {
final List<Account> r = rs.toList();
return r.size() == 1 ? r.get(0) : null;
}
}

View File

@@ -85,4 +85,8 @@ public class GroupControl {
public boolean canRemove(final Account.Id id) {
return isOwner();
}
public boolean canSee(Account.Id id) {
return isOwner();
}
}

View File

@@ -35,7 +35,9 @@ import com.google.gerrit.server.GerritServer;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.MimeUtilFileTypeRegistry;
import com.google.gerrit.server.account.AccountByEmailCache;
import com.google.gerrit.server.account.AccountCache2;
import com.google.gerrit.server.account.AccountCache;
import com.google.gerrit.server.account.AccountInfoCacheFactory;
import com.google.gerrit.server.account.AccountResolver;
import com.google.gerrit.server.account.GroupCache;
import com.google.gerrit.server.mail.AbandonedSender;
import com.google.gerrit.server.mail.AddReviewerSender;
@@ -90,11 +92,13 @@ public class GerritServerModule extends FactoryModule {
bind(CacheManager.class).toProvider(CacheManagerProvider.class).in(
SINGLETON);
bind(AccountByEmailCache.class);
bind(AccountCache2.class);
bind(AccountCache.class);
factory(AccountInfoCacheFactory.Factory.class);
bind(DiffCache.class);
bind(GroupCache.class);
bind(ProjectCache.class);
bind(SshKeyCache.class);
bind(AccountResolver.class);
bind(GerritServer.class);
bind(ContactStore.class).toProvider(EncryptedContactStoreProvider.class)

View File

@@ -26,9 +26,9 @@ import com.google.gerrit.client.reviewdb.PatchSetInfo;
import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.client.reviewdb.StarredChange;
import com.google.gerrit.client.reviewdb.UserIdentity;
import com.google.gerrit.client.rpc.Common;
import com.google.gerrit.server.GerritServer;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.account.AccountCache;
import com.google.gerrit.server.config.CanonicalWebUrl;
import com.google.gerrit.server.config.Nullable;
import com.google.gerrit.server.patch.PatchSetInfoFactory;
@@ -83,6 +83,9 @@ public abstract class OutgoingEmail {
@Inject
private ProjectCache projectCache;
@Inject
private AccountCache accountCache;
@Inject
private EmailSender emailSender;
@@ -435,11 +438,7 @@ public abstract class OutgoingEmail {
return "Anonymous Coward";
}
final Account userAccount = Common.getAccountCache().get(accountId);
if (userAccount == null) {
return "Anonymous Coward #" + accountId;
}
final Account userAccount = accountCache.get(accountId).getAccount();
String name = userAccount.getFullName();
if (name == null) {
name = userAccount.getPreferredEmail();
@@ -607,16 +606,11 @@ public abstract class OutgoingEmail {
}
private Address toAddress(final Account.Id id) {
final Account a = Common.getAccountCache().get(id);
if (a == null) {
return null;
}
final Account a = accountCache.get(id).getAccount();
final String e = a.getPreferredEmail();
if (e == null) {
return null;
}
return new Address(a.getFullName(), e);
}
}

View File

@@ -24,10 +24,10 @@ import com.google.gerrit.client.reviewdb.Account;
import com.google.gerrit.client.reviewdb.AccountExternalId;
import com.google.gerrit.client.reviewdb.AccountExternalIdAccess;
import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.client.rpc.Common;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.UrlEncoded;
import com.google.gerrit.server.account.AccountByEmailCache;
import com.google.gerrit.server.account.AccountCache2;
import com.google.gerrit.server.account.AccountCache;
import com.google.gerrit.server.config.AuthConfig;
import com.google.gerrit.server.config.CanonicalWebUrl;
import com.google.gerrit.server.config.Nullable;
@@ -101,21 +101,24 @@ class OpenIdServiceImpl implements OpenIdService {
"http://schema.openid.net/namePerson/last";
private final Provider<GerritCall> callFactory;
private final Provider<IdentifiedUser> identifiedUser;
private final AuthConfig authConfig;
private final Provider<String> urlProvider;
private final SchemaFactory<ReviewDb> schema;
private final ConsumerManager manager;
private final AccountByEmailCache byEmailCache;
private final AccountCache2 byIdCache;
private final AccountCache byIdCache;
private final SelfPopulatingCache discoveryCache;
@Inject
OpenIdServiceImpl(final Provider<GerritCall> cf, final AuthConfig ac,
OpenIdServiceImpl(final Provider<GerritCall> cf,
final Provider<IdentifiedUser> iu, final AuthConfig ac,
@CanonicalWebUrl @Nullable final Provider<String> up,
final AccountByEmailCache bec, final AccountCache2 bic,
final AccountByEmailCache bec, final AccountCache bic,
final CacheManager cacheMgr, final SchemaFactory<ReviewDb> sf)
throws ConsumerException {
callFactory = cf;
identifiedUser = iu;
authConfig = ac;
urlProvider = up;
schema = sf;
@@ -448,7 +451,7 @@ class OpenIdServiceImpl implements OpenIdService {
}
acctExt.setLastUsedOn();
extAccess.update(Collections.singleton(acctExt));
account = Common.getAccountCache().get(acctExt.getAccountId(), db);
account = byIdCache.get(acctExt.getAccountId()).getAccount();
} else {
account = null;
}
@@ -479,12 +482,7 @@ class OpenIdServiceImpl implements OpenIdService {
private Account linkAccount(final HttpServletRequest req, final ReviewDb db,
final Identifier user, final String curEmail) throws OrmException {
final Account.Id me = callFactory.get().getAccountId();
final Account account = Common.getAccountCache().get(me, db);
if (account == null) {
return null;
}
final Account account = identifiedUser.get().getAccount();
final AccountExternalId.Key idKey =
new AccountExternalId.Key(account.getId(), user.getIdentifier());
AccountExternalId id = db.accountExternalIds().get(idKey);

View File

@@ -17,7 +17,6 @@ package com.google.gerrit.server.rpc;
import com.google.gerrit.client.changes.ChangeListService;
import com.google.gerrit.client.changes.ToggleStarRequest;
import com.google.gerrit.client.data.AccountDashboardInfo;
import com.google.gerrit.client.data.AccountInfoCacheFactory;
import com.google.gerrit.client.data.ChangeInfo;
import com.google.gerrit.client.data.SingleListChangeInfo;
import com.google.gerrit.client.reviewdb.Account;
@@ -31,10 +30,10 @@ import com.google.gerrit.client.reviewdb.Project;
import com.google.gerrit.client.reviewdb.RevId;
import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.client.reviewdb.StarredChange;
import com.google.gerrit.client.rpc.Common;
import com.google.gerrit.client.rpc.NoSuchEntityException;
import com.google.gerrit.server.BaseServiceImplementation;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.account.AccountInfoCacheFactory;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gwt.user.client.rpc.AsyncCallback;
@@ -88,14 +87,17 @@ public class ChangeListServiceImpl extends BaseServiceImplementation implements
private final Provider<CurrentUser> currentUser;
private final ChangeControl.Factory changeControlFactory;
private final AccountInfoCacheFactory.Factory accountInfoCacheFactory;
@Inject
ChangeListServiceImpl(final Provider<ReviewDb> schema,
final Provider<CurrentUser> currentUser,
final ChangeControl.Factory changeControlFactory) {
final ChangeControl.Factory changeControlFactory,
final AccountInfoCacheFactory.Factory accountInfoCacheFactory) {
super(schema, currentUser);
this.currentUser = currentUser;
this.changeControlFactory = changeControlFactory;
this.accountInfoCacheFactory = accountInfoCacheFactory;
}
private boolean canRead(final Change c) {
@@ -278,7 +280,7 @@ public class ChangeListServiceImpl extends BaseServiceImplementation implements
run(callback, new Action<AccountDashboardInfo>() {
public AccountDashboardInfo run(final ReviewDb db) throws OrmException,
Failure {
final AccountInfoCacheFactory ac = new AccountInfoCacheFactory(db);
final AccountInfoCacheFactory ac = accountInfoCacheFactory.create();
final Account user = ac.get(target);
if (user == null) {
throw new Failure(new NoSuchEntityException());
@@ -326,7 +328,7 @@ public class ChangeListServiceImpl extends BaseServiceImplementation implements
run(callback, new Action<SingleListChangeInfo>() {
public SingleListChangeInfo run(final ReviewDb db) throws OrmException {
final Account.Id me = getAccountId();
final AccountInfoCacheFactory ac = new AccountInfoCacheFactory(db);
final AccountInfoCacheFactory ac = accountInfoCacheFactory.create();
final SingleListChangeInfo d = new SingleListChangeInfo();
final Set<Change.Id> starred = currentUser.get().getStarredChanges();
d.setChanges(filter(db.changes().get(starred), starred, ac));
@@ -345,7 +347,7 @@ public class ChangeListServiceImpl extends BaseServiceImplementation implements
run(callback, new Action<SingleListChangeInfo>() {
public SingleListChangeInfo run(final ReviewDb db) throws OrmException {
final Account.Id me = getAccountId();
final AccountInfoCacheFactory ac = new AccountInfoCacheFactory(db);
final AccountInfoCacheFactory ac = accountInfoCacheFactory.create();
final SingleListChangeInfo d = new SingleListChangeInfo();
final Set<Change.Id> starred = currentUser.get().getStarredChanges();
final Set<Change.Id> drafted = draftedBy(db, me);
@@ -406,7 +408,8 @@ public class ChangeListServiceImpl extends BaseServiceImplementation implements
final ArrayList<ChangeInfo> r = new ArrayList<ChangeInfo>();
for (final Change c : rs) {
if (canRead(c)) {
final ChangeInfo ci = new ChangeInfo(c, accts);
final ChangeInfo ci = new ChangeInfo(c);
accts.want(ci.getOwner());
ci.setStarred(starred.contains(ci.getId()));
r.add(ci);
}
@@ -504,7 +507,7 @@ public class ChangeListServiceImpl extends BaseServiceImplementation implements
public SingleListChangeInfo run(final ReviewDb db) throws OrmException {
final Account.Id me = getAccountId();
final AccountInfoCacheFactory ac = new AccountInfoCacheFactory(db);
final AccountInfoCacheFactory ac = accountInfoCacheFactory.create();
final SingleListChangeInfo d = new SingleListChangeInfo();
final Set<Change.Id> starred = currentUser.get().getStarredChanges();
@@ -517,7 +520,8 @@ public class ChangeListServiceImpl extends BaseServiceImplementation implements
for (final Change c : rs) {
results = true;
if (canRead(c)) {
final ChangeInfo ci = new ChangeInfo(c, ac);
final ChangeInfo ci = new ChangeInfo(c);
ac.want(ci.getOwner());
ci.setStarred(starred.contains(ci.getId()));
list.add(ci);
if (list.size() == slim) {

View File

@@ -14,17 +14,16 @@
package com.google.gerrit.server.rpc;
import com.google.gerrit.client.data.AccountCache;
import com.google.gerrit.client.data.AccountInfo;
import com.google.gerrit.client.reviewdb.Account;
import com.google.gerrit.client.reviewdb.AccountExternalId;
import com.google.gerrit.client.reviewdb.AccountGroup;
import com.google.gerrit.client.reviewdb.Project;
import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.client.rpc.Common;
import com.google.gerrit.client.ui.SuggestService;
import com.google.gerrit.server.BaseServiceImplementation;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.account.AccountCache;
import com.google.gerrit.server.project.ProjectCache;
import com.google.gerrit.server.project.ProjectState;
import com.google.gwt.user.client.rpc.AsyncCallback;
@@ -40,14 +39,17 @@ class SuggestServiceImpl extends BaseServiceImplementation implements
SuggestService {
private static final String MAX_SUFFIX = "\u9fa5";
private final Provider<CurrentUser> currentUser;
private final ProjectCache projectCache;
private final AccountCache accountCache;
private final Provider<CurrentUser> currentUser;
@Inject
SuggestServiceImpl(final Provider<ReviewDb> schema, final ProjectCache pc,
SuggestServiceImpl(final Provider<ReviewDb> schema,
final ProjectCache projectCache, final AccountCache accountCache,
final Provider<CurrentUser> currentUser) {
super(schema, currentUser);
this.projectCache = pc;
this.projectCache = projectCache;
this.accountCache = accountCache;
this.currentUser = currentUser;
}
@@ -94,16 +96,13 @@ class SuggestServiceImpl extends BaseServiceImplementation implements
}
}
if (r.size() < n) {
final AccountCache ac = Common.getAccountCache();
for (final AccountExternalId e : db.accountExternalIds()
.suggestByEmailAddress(a, b, n - r.size())) {
if (!r.containsKey(e.getAccountId())) {
final Account p = ac.get(e.getAccountId(), db);
if (p != null) {
final AccountInfo info = new AccountInfo(p);
info.setPreferredEmail(e.getEmailAddress());
r.put(e.getAccountId(), info);
}
final Account p = accountCache.get(e.getAccountId()).getAccount();
final AccountInfo info = new AccountInfo(p);
info.setPreferredEmail(e.getEmailAddress());
r.put(e.getAccountId(), info);
}
}
}

View File

@@ -30,7 +30,6 @@ public class UiRpcModule extends RpcServletModule {
@Override
protected void configureServlets() {
rpc(GroupAdminServiceImpl.class);
rpc(ChangeListServiceImpl.class);
rpc(SuggestServiceImpl.class);
rpc(SystemInfoServiceImpl.class);

View File

@@ -30,9 +30,11 @@ public class AccountModule extends RpcServletModule {
protected void configure() {
factory(AgreementInfoFactory.Factory.class);
factory(ExternalIdDetailFactory.Factory.class);
factory(GroupDetailFactory.Factory.class);
}
});
rpc(AccountSecurityImpl.class);
rpc(AccountServiceImpl.class);
rpc(GroupAdminServiceImpl.class);
}
}

View File

@@ -22,7 +22,6 @@ import com.google.gerrit.client.reviewdb.AccountSshKey;
import com.google.gerrit.client.reviewdb.ContactInformation;
import com.google.gerrit.client.reviewdb.ContributorAgreement;
import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.client.rpc.Common;
import com.google.gerrit.client.rpc.ContactInformationStoreException;
import com.google.gerrit.client.rpc.InvalidSshKeyException;
import com.google.gerrit.client.rpc.NoSuchEntityException;
@@ -30,7 +29,7 @@ import com.google.gerrit.server.BaseServiceImplementation;
import com.google.gerrit.server.ContactStore;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.account.AccountByEmailCache;
import com.google.gerrit.server.account.AccountCache2;
import com.google.gerrit.server.account.AccountCache;
import com.google.gerrit.server.config.AuthConfig;
import com.google.gerrit.server.mail.EmailException;
import com.google.gerrit.server.mail.RegisterNewEmailSender;
@@ -69,7 +68,7 @@ class AccountSecurityImpl extends BaseServiceImplementation implements
private final RegisterNewEmailSender.Factory registerNewEmailFactory;
private final SshKeyCache sshKeyCache;
private final AccountByEmailCache byEmailCache;
private final AccountCache2 accountCache;
private final AccountCache accountCache;
private final boolean useContactInfo;
private final ExternalIdDetailFactory.Factory externalIdDetailFactory;
@@ -79,7 +78,7 @@ class AccountSecurityImpl extends BaseServiceImplementation implements
final Provider<CurrentUser> currentUser, final ContactStore cs,
final AuthConfig ac, final RegisterNewEmailSender.Factory esf,
final SshKeyCache skc, final AccountByEmailCache abec,
final AccountCache2 uac,
final AccountCache uac,
final ExternalIdDetailFactory.Factory externalIdDetailFactory) {
super(schema, currentUser);
contactStore = cs;
@@ -130,7 +129,7 @@ class AccountSecurityImpl extends BaseServiceImplementation implements
throw new Failure(new InvalidSshKeyException());
}
db.accountSshKeys().insert(Collections.singleton(newKey));
uncacheSshKeys(me, db);
uncacheSshKeys(me);
return newKey;
}
});
@@ -151,7 +150,7 @@ class AccountSecurityImpl extends BaseServiceImplementation implements
final Transaction txn = db.beginTransaction();
db.accountSshKeys().delete(k, txn);
txn.commit();
uncacheSshKeys(me, db);
uncacheSshKeys(me);
}
return VoidResult.INSTANCE;
@@ -159,17 +158,12 @@ class AccountSecurityImpl extends BaseServiceImplementation implements
});
}
private void uncacheSshKeys(final Account.Id me, final ReviewDb db) {
final Account a = Common.getAccountCache().get(me, db);
if (a != null) {
uncacheSshKeys(a.getSshUserName());
}
private void uncacheSshKeys(final Account.Id me) {
uncacheSshKeys(accountCache.get(me).getAccount().getSshUserName());
}
private void uncacheSshKeys(final String userName) {
if (userName != null) {
sshKeyCache.evict(userName);
}
sshKeyCache.evict(userName);
}
public void myExternalIds(AsyncCallback<List<AccountExternalId>> callback) {
@@ -266,7 +260,6 @@ class AccountSecurityImpl extends BaseServiceImplementation implements
byEmailCache.evict(me.getPreferredEmail());
}
accountCache.evict(me.getId());
Common.getAccountCache().invalidate(me.getId());
return me;
}
});
@@ -289,8 +282,7 @@ class AccountSecurityImpl extends BaseServiceImplementation implements
}
final AccountAgreement a =
new AccountAgreement(new AccountAgreement.Key(
getAccountId(), id));
new AccountAgreement(new AccountAgreement.Key(getAccountId(), id));
if (cla.isAutoVerify()) {
a.review(AccountAgreement.Status.VERIFIED, null);
}
@@ -366,7 +358,6 @@ class AccountSecurityImpl extends BaseServiceImplementation implements
byEmailCache.evict(oldEmail);
byEmailCache.evict(newEmail);
accountCache.evict(me);
Common.getAccountCache().invalidate(me);
return VoidResult.INSTANCE;
}
});

View File

@@ -22,11 +22,10 @@ import com.google.gerrit.client.reviewdb.AccountGeneralPreferences;
import com.google.gerrit.client.reviewdb.AccountProjectWatch;
import com.google.gerrit.client.reviewdb.Project;
import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.client.rpc.Common;
import com.google.gerrit.client.rpc.NoSuchEntityException;
import com.google.gerrit.server.BaseServiceImplementation;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.account.AccountCache2;
import com.google.gerrit.server.account.AccountCache;
import com.google.gerrit.server.project.NoSuchProjectException;
import com.google.gerrit.server.project.ProjectControl;
import com.google.gwt.user.client.rpc.AsyncCallback;
@@ -45,14 +44,14 @@ import java.util.Set;
class AccountServiceImpl extends BaseServiceImplementation implements
AccountService {
private final Provider<IdentifiedUser> currentUser;
private final AccountCache2 accountCache;
private final AccountCache accountCache;
private final ProjectControl.Factory projectControlFactory;
private final AgreementInfoFactory.Factory agreementInfoFactory;
@Inject
AccountServiceImpl(final Provider<ReviewDb> schema,
final Provider<IdentifiedUser> identifiedUser,
final AccountCache2 accountCache,
final AccountCache accountCache,
final ProjectControl.Factory projectControlFactory,
final AgreementInfoFactory.Factory agreementInfoFactory) {
super(schema, identifiedUser);
@@ -77,7 +76,6 @@ class AccountServiceImpl extends BaseServiceImplementation implements
a.setGeneralPreferences(pref);
db.accounts().update(Collections.singleton(a));
accountCache.evict(a.getId());
Common.getAccountCache().invalidate(a.getId());
return VoidResult.INSTANCE;
}
});

View File

@@ -12,23 +12,22 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.rpc;
package com.google.gerrit.server.rpc.account;
import com.google.gerrit.client.admin.AccountGroupDetail;
import com.google.gerrit.client.admin.GroupAdminService;
import com.google.gerrit.client.data.AccountInfoCacheFactory;
import com.google.gerrit.client.admin.GroupDetail;
import com.google.gerrit.client.reviewdb.Account;
import com.google.gerrit.client.reviewdb.AccountGroup;
import com.google.gerrit.client.reviewdb.AccountGroupMember;
import com.google.gerrit.client.reviewdb.AccountGroupMemberAudit;
import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.client.rpc.Common;
import com.google.gerrit.client.rpc.NameAlreadyUsedException;
import com.google.gerrit.client.rpc.NoSuchAccountException;
import com.google.gerrit.client.rpc.NoSuchEntityException;
import com.google.gerrit.server.BaseServiceImplementation;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.account.AccountCache2;
import com.google.gerrit.server.account.AccountCache;
import com.google.gerrit.server.account.AccountResolver;
import com.google.gerrit.server.account.GroupCache;
import com.google.gerrit.server.account.GroupControl;
import com.google.gerrit.server.account.NoSuchGroupException;
@@ -49,20 +48,26 @@ import java.util.Set;
class GroupAdminServiceImpl extends BaseServiceImplementation implements
GroupAdminService {
private final Provider<IdentifiedUser> identifiedUser;
private final AccountCache2 accountCache;
private final AccountCache accountCache;
private final AccountResolver accountResolver;
private final GroupCache groupCache;
private final GroupControl.Factory groupControlFactory;
private final GroupDetailFactory.Factory groupDetailFactory;
@Inject
GroupAdminServiceImpl(final Provider<ReviewDb> schema,
final Provider<IdentifiedUser> currentUser,
final AccountCache2 accountCache, final GroupCache groupCache,
final GroupControl.Factory groupControlFactory) {
final AccountCache accountCache, final AccountResolver accountResolver,
final GroupCache groupCache,
final GroupControl.Factory groupControlFactory,
final GroupDetailFactory.Factory groupDetailFactory) {
super(schema, currentUser);
this.identifiedUser = currentUser;
this.accountCache = accountCache;
this.accountResolver = accountResolver;
this.groupCache = groupCache;
this.groupControlFactory = groupControlFactory;
this.groupDetailFactory = groupDetailFactory;
}
public void ownedGroups(final AsyncCallback<List<AccountGroup>> callback) {
@@ -137,17 +142,8 @@ class GroupAdminServiceImpl extends BaseServiceImplementation implements
}
public void groupDetail(final AccountGroup.Id groupId,
final AsyncCallback<AccountGroupDetail> callback) {
run(callback, new Action<AccountGroupDetail>() {
public AccountGroupDetail run(ReviewDb db) throws OrmException, Failure {
final AccountGroup group = db.accountGroups().get(groupId);
assertAmGroupOwner(db, group);
final AccountGroupDetail d = new AccountGroupDetail();
d.load(db, new AccountInfoCacheFactory(db), group);
return d;
}
});
final AsyncCallback<GroupDetail> callback) {
groupDetailFactory.create(groupId).to(callback);
}
public void changeGroupDescription(final AccountGroup.Id groupId,
@@ -207,16 +203,16 @@ class GroupAdminServiceImpl extends BaseServiceImplementation implements
}
public void addGroupMember(final AccountGroup.Id groupId,
final String nameOrEmail, final AsyncCallback<AccountGroupDetail> callback) {
run(callback, new Action<AccountGroupDetail>() {
public AccountGroupDetail run(ReviewDb db) throws OrmException, Failure,
final String nameOrEmail, final AsyncCallback<GroupDetail> callback) {
run(callback, new Action<GroupDetail>() {
public GroupDetail run(ReviewDb db) throws OrmException, Failure,
NoSuchGroupException {
final GroupControl control = groupControlFactory.validateFor(groupId);
if (control.getAccountGroup().isAutomaticMembership()) {
throw new Failure(new NameAlreadyUsedException());
}
final Account a = findAccount(db, nameOrEmail);
final Account a = findAccount(nameOrEmail);
if (!control.canAdd(a.getId())) {
throw new Failure(new NoSuchEntityException());
}
@@ -235,9 +231,7 @@ class GroupAdminServiceImpl extends BaseServiceImplementation implements
accountCache.evict(m.getAccountId());
}
final AccountGroupDetail d = new AccountGroupDetail();
d.loadOneMember(db, a, m);
return d;
return groupDetailFactory.create(groupId).call();
}
});
}
@@ -308,9 +302,9 @@ class GroupAdminServiceImpl extends BaseServiceImplementation implements
}
}
private static Account findAccount(final ReviewDb db, final String nameOrEmail)
throws OrmException, Failure {
final Account r = Account.find(db, nameOrEmail);
private Account findAccount(final String nameOrEmail) throws OrmException,
Failure {
final Account r = accountResolver.find(nameOrEmail);
if (r == null) {
throw new Failure(new NoSuchAccountException(nameOrEmail));
}

View File

@@ -0,0 +1,109 @@
// Copyright (C) 2009 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.rpc.account;
import com.google.gerrit.client.admin.GroupDetail;
import com.google.gerrit.client.reviewdb.Account;
import com.google.gerrit.client.reviewdb.AccountGroup;
import com.google.gerrit.client.reviewdb.AccountGroupMember;
import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.server.account.AccountInfoCacheFactory;
import com.google.gerrit.server.account.GroupCache;
import com.google.gerrit.server.account.GroupControl;
import com.google.gerrit.server.account.NoSuchGroupException;
import com.google.gerrit.server.rpc.Handler;
import com.google.gwtorm.client.OrmException;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
class GroupDetailFactory extends Handler<GroupDetail> {
interface Factory {
GroupDetailFactory create(AccountGroup.Id groupId);
}
private final ReviewDb db;
private final GroupControl.Factory groupControl;
private final GroupCache groupCache;
private final AccountInfoCacheFactory aic;
private final AccountGroup.Id groupId;
private GroupControl control;
@Inject
GroupDetailFactory(final ReviewDb db,
final GroupControl.Factory groupControl, final GroupCache groupCache,
final AccountInfoCacheFactory.Factory accountInfoCacheFactory,
@Assisted final AccountGroup.Id groupId) {
this.db = db;
this.groupControl = groupControl;
this.groupCache = groupCache;
this.aic = accountInfoCacheFactory.create();
this.groupId = groupId;
}
@Override
public GroupDetail call() throws OrmException, NoSuchGroupException {
control = groupControl.validateFor(groupId);
final AccountGroup group = control.getAccountGroup();
final GroupDetail detail = new GroupDetail();
detail.setGroup(group);
detail.setOwnerGroup(groupCache.get(group.getOwnerGroupId()));
if (!group.isAutomaticMembership()) {
detail.setMembers(loadMembers());
}
detail.setAccounts(aic.create());
return detail;
}
private List<AccountGroupMember> loadMembers() throws OrmException {
List<AccountGroupMember> members = new ArrayList<AccountGroupMember>();
for (final AccountGroupMember m : db.accountGroupMembers().byGroup(groupId)) {
if (control.canSee(m.getAccountId())) {
aic.want(m.getAccountId());
members.add(m);
}
}
Collections.sort(members, new Comparator<AccountGroupMember>() {
public int compare(final AccountGroupMember o1,
final AccountGroupMember o2) {
final Account a = aic.get(o1.getAccountId());
final Account b = aic.get(o2.getAccountId());
return n(a).compareTo(n(b));
}
private String n(final Account a) {
String n = a.getFullName();
if (n != null && n.length() > 0) {
return n;
}
n = a.getPreferredEmail();
if (n != null && n.length() > 0) {
return n;
}
return a.getId().toString();
}
});
return members;
}
}

View File

@@ -14,7 +14,6 @@
package com.google.gerrit.server.rpc.changedetail;
import com.google.gerrit.client.data.AccountInfoCacheFactory;
import com.google.gerrit.client.data.ApprovalDetail;
import com.google.gerrit.client.data.ApprovalType;
import com.google.gerrit.client.data.ChangeDetail;
@@ -31,6 +30,7 @@ import com.google.gerrit.client.reviewdb.Project;
import com.google.gerrit.client.reviewdb.RevId;
import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.client.rpc.NoSuchEntityException;
import com.google.gerrit.server.account.AccountInfoCacheFactory;
import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.project.NoSuchChangeException;
@@ -60,11 +60,11 @@ class ChangeDetailFactory extends Handler<ChangeDetail> {
private final ChangeControl.Factory changeControlFactory;
private final FunctionState.Factory functionState;
private final PatchSetDetailFactory.Factory patchSetDetail;
private final AccountInfoCacheFactory aic;
private final ReviewDb db;
private final Change.Id changeId;
private AccountInfoCacheFactory acc;
private ChangeDetail detail;
private ChangeControl control;
@@ -73,12 +73,14 @@ class ChangeDetailFactory extends Handler<ChangeDetail> {
final FunctionState.Factory functionState,
final PatchSetDetailFactory.Factory patchSetDetail, final ReviewDb db,
final ChangeControl.Factory changeControlFactory,
final AccountInfoCacheFactory.Factory accountInfoCacheFactory,
@Assisted final Change.Id id) {
this.gerritConfig = gerritConfig;
this.functionState = functionState;
this.patchSetDetail = patchSetDetail;
this.db = db;
this.changeControlFactory = changeControlFactory;
this.aic = accountInfoCacheFactory.create();
this.changeId = id;
}
@@ -94,8 +96,7 @@ class ChangeDetailFactory extends Handler<ChangeDetail> {
throw new NoSuchEntityException();
}
acc = new AccountInfoCacheFactory(db);
acc.want(change.getOwner());
aic.want(change.getOwner());
detail = new ChangeDetail();
detail.setChange(change);
@@ -109,7 +110,7 @@ class ChangeDetailFactory extends Handler<ChangeDetail> {
loadCurrentPatchSet();
}
load();
detail.setAccounts(acc.create());
detail.setAccounts(aic.create());
return detail;
}
@@ -120,7 +121,7 @@ class ChangeDetailFactory extends Handler<ChangeDetail> {
private void loadMessages() throws OrmException {
detail.setMessages(db.changeMessages().byChange(changeId).toList());
for (final ChangeMessage m : detail.getMessages()) {
acc.want(m.getAuthor());
aic.want(m.getAuthor());
}
}
@@ -172,7 +173,7 @@ class ChangeDetailFactory extends Handler<ChangeDetail> {
ad.get(owner).sortFirst();
}
acc.want(ad.keySet());
aic.want(ad.keySet());
detail.setApprovals(ad.values());
}
@@ -210,7 +211,8 @@ class ChangeDetailFactory extends Handler<ChangeDetail> {
for (final Change.Id a : ancestorOrder) {
final Change ac = m.get(a);
if (ac != null) {
dependsOn.add(new ChangeInfo(ac, acc));
aic.want(ac.getOwner());
dependsOn.add(new ChangeInfo(ac));
}
}
@@ -218,7 +220,8 @@ class ChangeDetailFactory extends Handler<ChangeDetail> {
for (final PatchSetAncestor a : descendants) {
final Change ac = m.get(a.getPatchSet().getParentKey());
if (ac != null) {
neededBy.add(new ChangeInfo(ac, acc));
aic.want(ac.getOwner());
neededBy.add(new ChangeInfo(ac));
}
}

View File

@@ -16,7 +16,6 @@ package com.google.gerrit.server.rpc.changedetail;
import com.google.gerrit.client.changes.PatchSetPublishDetail;
import com.google.gerrit.client.data.AccountInfoCache;
import com.google.gerrit.client.data.AccountInfoCacheFactory;
import com.google.gerrit.client.data.ApprovalType;
import com.google.gerrit.client.data.GerritConfig;
import com.google.gerrit.client.reviewdb.AccountGroup;
@@ -30,6 +29,7 @@ import com.google.gerrit.client.reviewdb.PatchSetInfo;
import com.google.gerrit.client.reviewdb.ProjectRight;
import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.account.AccountInfoCacheFactory;
import com.google.gerrit.server.patch.PatchSetInfoFactory;
import com.google.gerrit.server.patch.PatchSetInfoNotAvailableException;
import com.google.gerrit.server.project.ChangeControl;
@@ -58,6 +58,7 @@ final class PatchSetPublishDetailFactory extends Handler<PatchSetPublishDetail>
private final GerritConfig gerritConfig;
private final ReviewDb db;
private final ChangeControl.Factory changeControlFactory;
private final AccountInfoCacheFactory aic;
private final IdentifiedUser user;
private final PatchSet.Id patchSetId;
@@ -72,13 +73,16 @@ final class PatchSetPublishDetailFactory extends Handler<PatchSetPublishDetail>
@Inject
PatchSetPublishDetailFactory(final PatchSetInfoFactory infoFactory,
final ProjectCache projectCache, final GerritConfig gerritConfig,
final ReviewDb db, final ChangeControl.Factory changeControlFactory,
final ReviewDb db,
final AccountInfoCacheFactory.Factory accountInfoCacheFactory,
final ChangeControl.Factory changeControlFactory,
final IdentifiedUser user, @Assisted final PatchSet.Id patchSetId) {
this.projectCache = projectCache;
this.infoFactory = infoFactory;
this.gerritConfig = gerritConfig;
this.db = db;
this.changeControlFactory = changeControlFactory;
this.aic = accountInfoCacheFactory.create();
this.user = user;
this.patchSetId = patchSetId;
@@ -87,7 +91,6 @@ final class PatchSetPublishDetailFactory extends Handler<PatchSetPublishDetail>
@Override
public PatchSetPublishDetail call() throws OrmException,
PatchSetInfoNotAvailableException, NoSuchChangeException {
final AccountInfoCacheFactory acc = new AccountInfoCacheFactory(db);
final Change.Id changeId = patchSetId.getParentKey();
final ChangeControl control = changeControlFactory.validateFor(changeId);
change = control.getChange();
@@ -105,8 +108,8 @@ final class PatchSetPublishDetailFactory extends Handler<PatchSetPublishDetail>
}
}
acc.want(change.getOwner());
accounts = acc.create();
aic.want(change.getOwner());
accounts = aic.create();
PatchSetPublishDetail detail = new PatchSetPublishDetail();
detail.setAccounts(accounts);

View File

@@ -14,7 +14,6 @@
package com.google.gerrit.server.rpc.patch;
import com.google.gerrit.client.data.AccountInfoCacheFactory;
import com.google.gerrit.client.patches.CommentDetail;
import com.google.gerrit.client.reviewdb.Account;
import com.google.gerrit.client.reviewdb.Change;
@@ -23,6 +22,7 @@ import com.google.gerrit.client.reviewdb.PatchLineComment;
import com.google.gerrit.client.reviewdb.PatchSet;
import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.account.AccountInfoCacheFactory;
import com.google.gerrit.server.config.Nullable;
import com.google.gerrit.server.project.ChangeControl;
import com.google.gerrit.server.project.NoSuchChangeException;
@@ -41,6 +41,7 @@ class CommentDetailFactory extends Handler<CommentDetail> {
private final ReviewDb db;
private final ChangeControl.Factory changeControlFactory;
private final AccountInfoCacheFactory aic;
private final Patch.Key patchKey;
private final PatchSet.Id psa;
@@ -54,11 +55,13 @@ class CommentDetailFactory extends Handler<CommentDetail> {
@Inject
CommentDetailFactory(final ReviewDb db,
final ChangeControl.Factory changeControlFactory,
final AccountInfoCacheFactory.Factory accountInfoCacheFactory,
@Assisted final Patch.Key patchKey,
@Assisted("patchSetA") @Nullable final PatchSet.Id patchSetA,
@Assisted("patchSetB") final PatchSet.Id patchSetB) {
this.db = db;
this.changeControlFactory = changeControlFactory;
this.aic = accountInfoCacheFactory.create();
this.patchKey = patchKey;
this.psa = patchSetA;
@@ -80,7 +83,6 @@ class CommentDetailFactory extends Handler<CommentDetail> {
}
final String pn = patch.getFileName();
final AccountInfoCacheFactory aic = new AccountInfoCacheFactory(db);
final CommentDetail r;
r = new CommentDetail(psa, psb != null ? psb : patchSetId);

View File

@@ -33,12 +33,12 @@ import com.google.gerrit.client.reviewdb.PatchSet;
import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.client.reviewdb.Account.Id;
import com.google.gerrit.client.reviewdb.Patch.Key;
import com.google.gerrit.client.rpc.Common;
import com.google.gerrit.client.rpc.NoSuchAccountException;
import com.google.gerrit.client.rpc.NoSuchEntityException;
import com.google.gerrit.server.BaseServiceImplementation;
import com.google.gerrit.server.ChangeUtil;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.account.AccountResolver;
import com.google.gerrit.server.mail.AddReviewerSender;
import com.google.gerrit.server.mail.CommentSender;
import com.google.gerrit.server.mail.EmailException;
@@ -69,6 +69,7 @@ class PatchDetailServiceImpl extends BaseServiceImplementation implements
private final CommentSender.Factory commentSenderFactory;
private final PatchSetInfoFactory patchSetInfoFactory;
private final GerritConfig gerritConfig;
private final AccountResolver accountResolver;
private final AbandonChange.Factory abandonChangeFactory;
private final CommentDetailFactory.Factory commentDetailFactory;
@@ -81,6 +82,8 @@ class PatchDetailServiceImpl extends BaseServiceImplementation implements
final Provider<CurrentUser> currentUser,
final AddReviewerSender.Factory arsf, final CommentSender.Factory csf,
final PatchSetInfoFactory psif, final GerritConfig gc,
final AccountResolver accountResolver,
final AbandonChange.Factory abandonChangeFactory,
final CommentDetailFactory.Factory commentDetailFactory,
final PatchScriptFactory.Factory patchScriptFactoryFactory,
@@ -90,6 +93,7 @@ class PatchDetailServiceImpl extends BaseServiceImplementation implements
addReviewerSenderFactory = arsf;
commentSenderFactory = csf;
gerritConfig = gc;
this.accountResolver = accountResolver;
this.abandonChangeFactory = abandonChangeFactory;
this.commentDetailFactory = commentDetailFactory;
@@ -327,7 +331,7 @@ class PatchDetailServiceImpl extends BaseServiceImplementation implements
}
for (final String email : reviewers) {
final Account who = Account.find(db, email);
final Account who = accountResolver.find(email);
if (who == null) {
throw new Failure(new NoSuchAccountException(email));
}

View File

@@ -16,7 +16,6 @@ package com.google.gerrit.server.rpc.project;
import com.google.gerrit.client.admin.ProjectAdminService;
import com.google.gerrit.client.admin.ProjectDetail;
import com.google.gerrit.client.reviewdb.Account;
import com.google.gerrit.client.reviewdb.AccountGroup;
import com.google.gerrit.client.reviewdb.ApprovalCategory;
import com.google.gerrit.client.reviewdb.ApprovalCategoryValue;
@@ -24,8 +23,6 @@ import com.google.gerrit.client.reviewdb.Branch;
import com.google.gerrit.client.reviewdb.Project;
import com.google.gerrit.client.reviewdb.ProjectRight;
import com.google.gerrit.client.reviewdb.ReviewDb;
import com.google.gerrit.client.reviewdb.AccountGroup.Id;
import com.google.gerrit.client.rpc.Common;
import com.google.gerrit.client.rpc.InvalidNameException;
import com.google.gerrit.client.rpc.InvalidRevisionException;
import com.google.gerrit.client.rpc.NoSuchEntityException;
@@ -395,10 +392,6 @@ class ProjectAdminServiceImpl extends BaseServiceImplementation implements
throw new Failure(new InvalidNameException());
}
final Account me = Common.getAccountCache().get(getAccountId());
if (me == null) {
throw new Failure(new NoSuchEntityException());
}
final ProjectState pce = projectCache.get(projectName);
if (pce == null) {
throw new Failure(new NoSuchEntityException());
@@ -463,7 +456,7 @@ class ProjectAdminServiceImpl extends BaseServiceImplementation implements
final RefUpdate u = repo.updateRef(refname);
u.setExpectedOldObjectId(ObjectId.zeroId());
u.setNewObjectId(revid);
u.setRefLogIdent(identifiedUser.get().toPersonIdent());
u.setRefLogIdent(identifiedUser.get().newPersonIdent());
u.setRefLogMessage("created via web from " + startingRevision,
false);
final RefUpdate.Result result = u.update(rw);

View File

@@ -58,6 +58,8 @@ public class SshKeyCache {
}
public void evict(String username) {
self.remove(username);
if (username != null) {
self.remove(username);
}
}
}

View File

@@ -14,7 +14,6 @@
package com.google.gerrit.server.ssh.commands;
import com.google.gerrit.client.rpc.Common;
import com.google.gerrit.server.patch.DiffCache;
import com.google.gerrit.server.ssh.AdminCommand;
import com.google.inject.Inject;
@@ -94,10 +93,6 @@ final class AdminFlushCaches extends CacheCommand {
private void doBulkFlush() {
try {
if (flush("accounts")) {
Common.getAccountCache().flush();
}
for (final Ehcache c : getAllCaches()) {
final String name = c.getName();
if (diffCache.getName().equals(name)) {

View File

@@ -15,7 +15,6 @@
package com.google.gerrit.server.ssh.commands;
import com.google.gerrit.client.reviewdb.Account;
import com.google.gerrit.client.rpc.Common;
import com.google.gerrit.server.ssh.AdminCommand;
import com.google.gerrit.server.ssh.BaseCommand;
import com.google.gerrit.server.ssh.SshDaemon;
@@ -24,8 +23,8 @@ import com.google.inject.Inject;
import org.apache.mina.core.service.IoAcceptor;
import org.apache.mina.core.session.IoSession;
import org.apache.sshd.common.session.AbstractSession;
import org.apache.sshd.server.CommandFactory.Command;
import org.apache.sshd.server.session.ServerSession;
import org.kohsuke.args4j.Option;
import java.io.PrintWriter;
@@ -88,7 +87,7 @@ final class AdminShowConnections extends BaseCommand {
"Remote Host"));
p.print("--------------------------------------------------------------\n");
for (final IoSession io : list) {
final AbstractSession s = AbstractSession.getSession(io, true);
ServerSession s = (ServerSession) ServerSession.getSession(io, true);
List<Command> active = s != null ? s.getAttribute(SshUtil.ACTIVE) : null;
final SocketAddress remoteAddress = io.getRemoteAddress();
@@ -131,19 +130,16 @@ final class AdminShowConnections extends BaseCommand {
return String.format("%02d:%02d:%02d", hr, min, sec);
}
private String username(final AbstractSession s) {
private String username(final ServerSession s) {
if (s == null) {
return "";
} else if (numeric) {
final Account.Id id = s.getAttribute(SshUtil.CURRENT_ACCOUNT);
return id != null ? "a/" + id.toString() : "";
} else {
final String user = s.getUsername();
return user != null ? user : "";
}
final Account.Id id = s.getAttribute(SshUtil.CURRENT_ACCOUNT);
if (id == null) {
return "";
}
if (numeric) {
return "a/" + id.toString();
}
final Account a = Common.getAccountCache().get(id);
return a != null ? a.getSshUserName() : "";
}
private String hostname(final SocketAddress remoteAddress) {

View File

@@ -30,7 +30,6 @@ abstract class CacheCommand extends BaseCommand {
protected SortedSet<String> cacheNames() {
final SortedSet<String> names = new TreeSet<String>();
names.add("accounts");
for (final Ehcache c : getAllCaches()) {
names.add(c.getName());
}

View File

@@ -188,7 +188,7 @@ final class Receive extends AbstractGitCommand {
verifyActiveContributorAgreement();
}
loadMyEmails();
refLogIdent = currentUser.toPersonIdent();
refLogIdent = currentUser.newPersonIdent();
rp = new ReceivePack(repo);
rp.setAllowCreates(true);

View File

@@ -24,7 +24,7 @@ import com.google.gerrit.client.reviewdb.ChangeApproval;
import com.google.gerrit.client.reviewdb.Project;
import com.google.gerrit.client.reviewdb.ProjectRight;
import com.google.gerrit.client.reviewdb.ApprovalCategory.Id;
import com.google.gerrit.server.account.AccountCache2;
import com.google.gerrit.server.account.AccountCache;
import com.google.gerrit.server.account.GroupCache;
import com.google.gerrit.server.project.ProjectCache;
import com.google.gerrit.server.project.ProjectState;
@@ -45,7 +45,7 @@ public class FunctionState {
FunctionState create(Change c, Collection<ChangeApproval> all);
}
private final AccountCache2 accountCache;
private final AccountCache accountCache;
private final ProjectCache projectCache;
private final Map<ApprovalCategory.Id, Collection<ChangeApproval>> approvals =
@@ -61,7 +61,7 @@ public class FunctionState {
private Set<ChangeApproval> modified;
@Inject
FunctionState(final ProjectCache pc, final AccountCache2 ac,
FunctionState(final ProjectCache pc, final AccountCache ac,
final GroupCache egc, @Assisted final Change c,
@Assisted final Collection<ChangeApproval> all) {
projectCache = pc;