CommentDetail/PatchScriptFactory: Remove unused AccountInfoCache
AccountInfoCache was populated but nobody used it. This was the last usage of AccountInfoCache, hence it can be removed now. Change-Id: I429e3e10bcd3b0148a272ec45d62c3babc80be1f Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -1,79 +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.common.data;
|
|
||||||
|
|
||||||
import com.google.gerrit.reviewdb.client.Account;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/** In-memory table of {@link AccountInfo}, indexed by {@code Account.Id}. */
|
|
||||||
public class AccountInfoCache {
|
|
||||||
private static final AccountInfoCache EMPTY;
|
|
||||||
static {
|
|
||||||
EMPTY = new AccountInfoCache();
|
|
||||||
EMPTY.accounts = Collections.emptyMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Obtain an empty cache singleton. */
|
|
||||||
public static AccountInfoCache empty() {
|
|
||||||
return EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Map<Account.Id, AccountInfo> accounts;
|
|
||||||
|
|
||||||
protected AccountInfoCache() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public AccountInfoCache(final Iterable<AccountInfo> list) {
|
|
||||||
accounts = new HashMap<>();
|
|
||||||
for (final AccountInfo ai : list) {
|
|
||||||
accounts.put(ai.getId(), ai);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Lookup the account summary
|
|
||||||
* <p>
|
|
||||||
* The return value can take on one of three forms:
|
|
||||||
* <ul>
|
|
||||||
* <li>{@code null}, if {@code id == null}.</li>
|
|
||||||
* <li>a valid info block, if {@code id} was loaded.</li>
|
|
||||||
* <li>an anonymous info block, if {@code id} was not loaded.</li>
|
|
||||||
* </ul>
|
|
||||||
*
|
|
||||||
* @param id the id desired.
|
|
||||||
* @return info block for the account.
|
|
||||||
*/
|
|
||||||
public AccountInfo get(final Account.Id id) {
|
|
||||||
if (id == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
AccountInfo r = accounts.get(id);
|
|
||||||
if (r == null) {
|
|
||||||
r = new AccountInfo(id);
|
|
||||||
accounts.put(id, r);
|
|
||||||
}
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Merge the information from another cache into this one. */
|
|
||||||
public void merge(final AccountInfoCache other) {
|
|
||||||
assert this != EMPTY;
|
|
||||||
accounts.putAll(other.accounts);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -27,7 +27,6 @@ import java.util.Map;
|
|||||||
public class CommentDetail {
|
public class CommentDetail {
|
||||||
protected List<Comment> a;
|
protected List<Comment> a;
|
||||||
protected List<Comment> b;
|
protected List<Comment> b;
|
||||||
protected AccountInfoCache accounts;
|
|
||||||
|
|
||||||
private transient PatchSet.Id idA;
|
private transient PatchSet.Id idA;
|
||||||
private transient PatchSet.Id idB;
|
private transient PatchSet.Id idB;
|
||||||
@@ -44,37 +43,23 @@ public class CommentDetail {
|
|||||||
protected CommentDetail() {
|
protected CommentDetail() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean include(Change.Id changeId, Comment p) {
|
public void include(Change.Id changeId, Comment p) {
|
||||||
PatchSet.Id psId = new PatchSet.Id(changeId, p.key.patchSetId);
|
PatchSet.Id psId = new PatchSet.Id(changeId, p.key.patchSetId);
|
||||||
switch (p.side) {
|
switch (p.side) {
|
||||||
case 0:
|
case 0:
|
||||||
if (idA == null && idB.equals(psId)) {
|
if (idA == null && idB.equals(psId)) {
|
||||||
a.add(p);
|
a.add(p);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
if (idA != null && idA.equals(psId)) {
|
if (idA != null && idA.equals(psId)) {
|
||||||
a.add(p);
|
a.add(p);
|
||||||
return true;
|
} else if (idB.equals(psId)) {
|
||||||
}
|
|
||||||
|
|
||||||
if (idB.equals(psId)) {
|
|
||||||
b.add(p);
|
b.add(p);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAccountInfoCache(final AccountInfoCache a) {
|
|
||||||
accounts = a;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AccountInfoCache getAccounts() {
|
|
||||||
return accounts;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Comment> getCommentsA() {
|
public List<Comment> getCommentsA() {
|
||||||
|
|||||||
@@ -1,75 +0,0 @@
|
|||||||
// 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.common.data.AccountInfo;
|
|
||||||
import com.google.gerrit.common.data.AccountInfoCache;
|
|
||||||
import com.google.gerrit.reviewdb.client.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<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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<>(out.size());
|
|
||||||
for (final Account a : out.values()) {
|
|
||||||
r.add(new AccountInfo(a));
|
|
||||||
}
|
|
||||||
return new AccountInfoCache(r);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -77,7 +77,6 @@ import com.google.gerrit.server.Sequences;
|
|||||||
import com.google.gerrit.server.account.AccountByEmailCacheImpl;
|
import com.google.gerrit.server.account.AccountByEmailCacheImpl;
|
||||||
import com.google.gerrit.server.account.AccountCacheImpl;
|
import com.google.gerrit.server.account.AccountCacheImpl;
|
||||||
import com.google.gerrit.server.account.AccountControl;
|
import com.google.gerrit.server.account.AccountControl;
|
||||||
import com.google.gerrit.server.account.AccountInfoCacheFactory;
|
|
||||||
import com.google.gerrit.server.account.AccountManager;
|
import com.google.gerrit.server.account.AccountManager;
|
||||||
import com.google.gerrit.server.account.AccountResolver;
|
import com.google.gerrit.server.account.AccountResolver;
|
||||||
import com.google.gerrit.server.account.AccountVisibility;
|
import com.google.gerrit.server.account.AccountVisibility;
|
||||||
@@ -241,7 +240,6 @@ public class GerritGlobalModule extends FactoryModule {
|
|||||||
|
|
||||||
bind(AccountResolver.class);
|
bind(AccountResolver.class);
|
||||||
|
|
||||||
factory(AccountInfoCacheFactory.Factory.class);
|
|
||||||
factory(AddReviewerSender.Factory.class);
|
factory(AddReviewerSender.Factory.class);
|
||||||
factory(DeleteReviewerSender.Factory.class);
|
factory(DeleteReviewerSender.Factory.class);
|
||||||
factory(AddKeySender.Factory.class);
|
factory(AddKeySender.Factory.class);
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
|
|||||||
import com.google.gerrit.server.CommentsUtil;
|
import com.google.gerrit.server.CommentsUtil;
|
||||||
import com.google.gerrit.server.CurrentUser;
|
import com.google.gerrit.server.CurrentUser;
|
||||||
import com.google.gerrit.server.PatchSetUtil;
|
import com.google.gerrit.server.PatchSetUtil;
|
||||||
import com.google.gerrit.server.account.AccountInfoCacheFactory;
|
|
||||||
import com.google.gerrit.server.edit.ChangeEdit;
|
import com.google.gerrit.server.edit.ChangeEdit;
|
||||||
import com.google.gerrit.server.edit.ChangeEditUtil;
|
import com.google.gerrit.server.edit.ChangeEditUtil;
|
||||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||||
@@ -87,7 +86,6 @@ public class PatchScriptFactory implements Callable<PatchScript> {
|
|||||||
private final Provider<PatchScriptBuilder> builderFactory;
|
private final Provider<PatchScriptBuilder> builderFactory;
|
||||||
private final PatchListCache patchListCache;
|
private final PatchListCache patchListCache;
|
||||||
private final ReviewDb db;
|
private final ReviewDb db;
|
||||||
private final AccountInfoCacheFactory.Factory aicFactory;
|
|
||||||
private final CommentsUtil commentsUtil;
|
private final CommentsUtil commentsUtil;
|
||||||
|
|
||||||
private final String fileName;
|
private final String fileName;
|
||||||
@@ -117,7 +115,6 @@ public class PatchScriptFactory implements Callable<PatchScript> {
|
|||||||
Provider<PatchScriptBuilder> builderFactory,
|
Provider<PatchScriptBuilder> builderFactory,
|
||||||
PatchListCache patchListCache,
|
PatchListCache patchListCache,
|
||||||
ReviewDb db,
|
ReviewDb db,
|
||||||
AccountInfoCacheFactory.Factory aicFactory,
|
|
||||||
CommentsUtil commentsUtil,
|
CommentsUtil commentsUtil,
|
||||||
ChangeEditUtil editReader,
|
ChangeEditUtil editReader,
|
||||||
@Assisted ChangeControl control,
|
@Assisted ChangeControl control,
|
||||||
@@ -131,7 +128,6 @@ public class PatchScriptFactory implements Callable<PatchScript> {
|
|||||||
this.patchListCache = patchListCache;
|
this.patchListCache = patchListCache;
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.control = control;
|
this.control = control;
|
||||||
this.aicFactory = aicFactory;
|
|
||||||
this.commentsUtil = commentsUtil;
|
this.commentsUtil = commentsUtil;
|
||||||
this.editReader = editReader;
|
this.editReader = editReader;
|
||||||
|
|
||||||
@@ -150,7 +146,6 @@ public class PatchScriptFactory implements Callable<PatchScript> {
|
|||||||
Provider<PatchScriptBuilder> builderFactory,
|
Provider<PatchScriptBuilder> builderFactory,
|
||||||
PatchListCache patchListCache,
|
PatchListCache patchListCache,
|
||||||
ReviewDb db,
|
ReviewDb db,
|
||||||
AccountInfoCacheFactory.Factory aicFactory,
|
|
||||||
CommentsUtil commentsUtil,
|
CommentsUtil commentsUtil,
|
||||||
ChangeEditUtil editReader,
|
ChangeEditUtil editReader,
|
||||||
@Assisted ChangeControl control,
|
@Assisted ChangeControl control,
|
||||||
@@ -164,7 +159,6 @@ public class PatchScriptFactory implements Callable<PatchScript> {
|
|||||||
this.patchListCache = patchListCache;
|
this.patchListCache = patchListCache;
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.control = control;
|
this.control = control;
|
||||||
this.aicFactory = aicFactory;
|
|
||||||
this.commentsUtil = commentsUtil;
|
this.commentsUtil = commentsUtil;
|
||||||
this.editReader = editReader;
|
this.editReader = editReader;
|
||||||
|
|
||||||
@@ -344,24 +338,23 @@ public class PatchScriptFactory implements Callable<PatchScript> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (loadComments && edit == null) {
|
if (loadComments && edit == null) {
|
||||||
AccountInfoCacheFactory aic = aicFactory.create();
|
|
||||||
comments = new CommentDetail(psa, psb);
|
comments = new CommentDetail(psa, psb);
|
||||||
switch (changeType) {
|
switch (changeType) {
|
||||||
case ADDED:
|
case ADDED:
|
||||||
case MODIFIED:
|
case MODIFIED:
|
||||||
loadPublished(byKey, aic, newName);
|
loadPublished(byKey, newName);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DELETED:
|
case DELETED:
|
||||||
loadPublished(byKey, aic, newName);
|
loadPublished(byKey, newName);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case COPIED:
|
case COPIED:
|
||||||
case RENAMED:
|
case RENAMED:
|
||||||
if (psa != null) {
|
if (psa != null) {
|
||||||
loadPublished(byKey, aic, oldName);
|
loadPublished(byKey, oldName);
|
||||||
}
|
}
|
||||||
loadPublished(byKey, aic, newName);
|
loadPublished(byKey, newName);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case REWRITE:
|
case REWRITE:
|
||||||
@@ -374,38 +367,33 @@ public class PatchScriptFactory implements Callable<PatchScript> {
|
|||||||
switch (changeType) {
|
switch (changeType) {
|
||||||
case ADDED:
|
case ADDED:
|
||||||
case MODIFIED:
|
case MODIFIED:
|
||||||
loadDrafts(byKey, aic, me, newName);
|
loadDrafts(byKey, me, newName);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DELETED:
|
case DELETED:
|
||||||
loadDrafts(byKey, aic, me, newName);
|
loadDrafts(byKey, me, newName);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case COPIED:
|
case COPIED:
|
||||||
case RENAMED:
|
case RENAMED:
|
||||||
if (psa != null) {
|
if (psa != null) {
|
||||||
loadDrafts(byKey, aic, me, oldName);
|
loadDrafts(byKey, me, oldName);
|
||||||
}
|
}
|
||||||
loadDrafts(byKey, aic, me, newName);
|
loadDrafts(byKey, me, newName);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case REWRITE:
|
case REWRITE:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
comments.setAccountInfoCache(aic.create());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadPublished(final Map<Patch.Key, Patch> byKey,
|
private void loadPublished(Map<Patch.Key, Patch> byKey, String file)
|
||||||
final AccountInfoCacheFactory aic, final String file) throws OrmException {
|
throws OrmException {
|
||||||
ChangeNotes notes = control.getNotes();
|
ChangeNotes notes = control.getNotes();
|
||||||
for (Comment c : commentsUtil.publishedByChangeFile(db, notes, changeId, file)) {
|
for (Comment c : commentsUtil.publishedByChangeFile(db, notes, changeId, file)) {
|
||||||
if (comments.include(change.getId(), c)) {
|
comments.include(change.getId(), c);
|
||||||
aic.want(c.author.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
PatchSet.Id psId = new PatchSet.Id(change.getId(), c.key.patchSetId);
|
PatchSet.Id psId = new PatchSet.Id(change.getId(), c.key.patchSetId);
|
||||||
Patch.Key pKey = new Patch.Key(psId, c.key.filename);
|
Patch.Key pKey = new Patch.Key(psId, c.key.filename);
|
||||||
Patch p = byKey.get(pKey);
|
Patch p = byKey.get(pKey);
|
||||||
@@ -415,15 +403,11 @@ public class PatchScriptFactory implements Callable<PatchScript> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadDrafts(final Map<Patch.Key, Patch> byKey,
|
private void loadDrafts(Map<Patch.Key, Patch> byKey, Account.Id me,
|
||||||
final AccountInfoCacheFactory aic, final Account.Id me, final String file)
|
String file) throws OrmException {
|
||||||
throws OrmException {
|
|
||||||
for (Comment c :
|
for (Comment c :
|
||||||
commentsUtil.draftByChangeFileAuthor(db, control.getNotes(), file, me)) {
|
commentsUtil.draftByChangeFileAuthor(db, control.getNotes(), file, me)) {
|
||||||
if (comments.include(change.getId(), c)) {
|
comments.include(change.getId(), c);
|
||||||
aic.want(me);
|
|
||||||
}
|
|
||||||
|
|
||||||
PatchSet.Id psId = new PatchSet.Id(change.getId(), c.key.patchSetId);
|
PatchSet.Id psId = new PatchSet.Id(change.getId(), c.key.patchSetId);
|
||||||
Patch.Key pKey = new Patch.Key(psId, c.key.filename);
|
Patch.Key pKey = new Patch.Key(psId, c.key.filename);
|
||||||
Patch p = byKey.get(pKey);
|
Patch p = byKey.get(pKey);
|
||||||
|
|||||||
Reference in New Issue
Block a user