Delete ChangeListService.allQueryNext

This RPC is no longer used by the web UI, it has been replaced
by the /changes/ REST API.

Change-Id: I6a91e6bf4e24709d070bc9c78a264163cc0ac96a
This commit is contained in:
Shawn O. Pearce
2012-04-07 14:23:07 -07:00
parent ef8214b271
commit 1283dd7d1c
2 changed files with 1 additions and 205 deletions

View File

@@ -24,14 +24,6 @@ import com.google.gwtjsonrpc.common.RpcImpl.Version;
@RpcImpl(version = Version.V2_0)
public interface ChangeListService extends RemoteJsonService {
/** Get all changes which match an arbitrary query string. */
void allQueryPrev(String query, String pos, int limit,
AsyncCallback<SingleListChangeInfo> callback);
/** Get all changes which match an arbitrary query string. */
void allQueryNext(String query, String pos, int limit,
AsyncCallback<SingleListChangeInfo> callback);
/** Get the data to show AccountDashboardScreen for an account. */
void forAccount(Account.Id id, AsyncCallback<AccountDashboardInfo> callback);

View File

@@ -17,10 +17,7 @@ package com.google.gerrit.httpd.rpc;
import com.google.gerrit.common.data.AccountDashboardInfo;
import com.google.gerrit.common.data.ChangeInfo;
import com.google.gerrit.common.data.ChangeListService;
import com.google.gerrit.common.data.GlobalCapability;
import com.google.gerrit.common.data.SingleListChangeInfo;
import com.google.gerrit.common.data.ToggleStarRequest;
import com.google.gerrit.common.errors.InvalidQueryException;
import com.google.gerrit.common.errors.NoSuchEntityException;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.reviewdb.client.Change;
@@ -32,15 +29,8 @@ 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.gerrit.server.query.Predicate;
import com.google.gerrit.server.query.QueryParseException;
import com.google.gerrit.server.query.change.ChangeData;
import com.google.gerrit.server.query.change.ChangeDataSource;
import com.google.gerrit.server.query.change.ChangeQueryBuilder;
import com.google.gerrit.server.query.change.ChangeQueryRewriter;
import com.google.gwtjsonrpc.common.AsyncCallback;
import com.google.gwtjsonrpc.common.VoidResult;
import com.google.gwtorm.server.ListResultSet;
import com.google.gwtorm.server.OrmException;
import com.google.gwtorm.server.ResultSet;
import com.google.inject.Inject;
@@ -67,39 +57,20 @@ public class ChangeListServiceImpl extends BaseServiceImplementation implements
return o2.getSortKey().compareTo(o1.getSortKey());
}
};
private static final Comparator<Change> QUERY_PREV =
new Comparator<Change>() {
public int compare(final Change a, final Change b) {
return a.getSortKey().compareTo(b.getSortKey());
}
};
private static final Comparator<Change> QUERY_NEXT =
new Comparator<Change>() {
public int compare(final Change a, final Change b) {
return b.getSortKey().compareTo(a.getSortKey());
}
};
private final Provider<CurrentUser> currentUser;
private final ChangeControl.Factory changeControlFactory;
private final AccountInfoCacheFactory.Factory accountInfoCacheFactory;
private final ChangeQueryBuilder.Factory queryBuilder;
private final Provider<ChangeQueryRewriter> queryRewriter;
@Inject
ChangeListServiceImpl(final Provider<ReviewDb> schema,
final Provider<CurrentUser> currentUser,
final ChangeControl.Factory changeControlFactory,
final AccountInfoCacheFactory.Factory accountInfoCacheFactory,
final ChangeQueryBuilder.Factory queryBuilder,
final Provider<ChangeQueryRewriter> queryRewriter) {
final AccountInfoCacheFactory.Factory accountInfoCacheFactory) {
super(schema, currentUser);
this.currentUser = currentUser;
this.changeControlFactory = changeControlFactory;
this.accountInfoCacheFactory = accountInfoCacheFactory;
this.queryBuilder = queryBuilder;
this.queryRewriter = queryRewriter;
}
private boolean canRead(final Change c, final ReviewDb db) throws OrmException {
@@ -110,99 +81,6 @@ public class ChangeListServiceImpl extends BaseServiceImplementation implements
}
}
@Override
public void allQueryPrev(final String query, final String pos,
final int pageSize, final AsyncCallback<SingleListChangeInfo> callback) {
try {
run(callback, new QueryPrev(pageSize, pos) {
@Override
ResultSet<Change> query(ReviewDb db, int lim, String key)
throws OrmException, InvalidQueryException {
return searchQuery(db, query, lim, key, QUERY_PREV);
}
});
} catch (InvalidQueryException e) {
callback.onFailure(e);
}
}
@Override
public void allQueryNext(final String query, final String pos,
final int pageSize, final AsyncCallback<SingleListChangeInfo> callback) {
try {
run(callback, new QueryNext(pageSize, pos) {
@Override
ResultSet<Change> query(ReviewDb db, int lim, String key)
throws OrmException, InvalidQueryException {
return searchQuery(db, query, lim, key, QUERY_NEXT);
}
});
} catch (InvalidQueryException e) {
callback.onFailure(e);
}
}
@SuppressWarnings("unchecked")
private ResultSet<Change> searchQuery(final ReviewDb db, String query,
final int limit, final String key, final Comparator<Change> cmp)
throws OrmException, InvalidQueryException {
try {
final ChangeQueryBuilder builder = queryBuilder.create(currentUser.get());
final Predicate<ChangeData> visibleToMe = builder.is_visible();
Predicate<ChangeData> q = builder.parse(query);
q = Predicate.and(q, //
cmp == QUERY_PREV //
? builder.sortkey_after(key) //
: builder.sortkey_before(key), //
builder.limit(limit), //
visibleToMe //
);
ChangeQueryRewriter rewriter = queryRewriter.get();
Predicate<ChangeData> s = rewriter.rewrite(q);
if (!(s instanceof ChangeDataSource)) {
s = rewriter.rewrite(Predicate.and(builder.status_open(), q));
}
if (s instanceof ChangeDataSource) {
ArrayList<Change> r = new ArrayList<Change>();
HashSet<Change.Id> want = new HashSet<Change.Id>();
for (ChangeData d : ((ChangeDataSource) s).read()) {
if (d.hasChange()) {
// Checking visibleToMe here should be unnecessary, the
// query should have already performed it. But we don't
// want to trust the query rewriter that much yet.
//
if (visibleToMe.match(d)) {
r.add(d.getChange());
}
} else {
want.add(d.getId());
}
}
// Here we have to check canRead. Its impossible to
// do that test without the change object, and it being
// missing above means we have to compute it ourselves.
//
if (!want.isEmpty()) {
for (Change c : db.changes().get(want)) {
if (canRead(c, db)) {
r.add(c);
}
}
}
Collections.sort(r, cmp);
return new ListResultSet<Change>(r);
} else {
throw new InvalidQueryException("Not Supported", s.toString());
}
} catch (QueryParseException e) {
throw new InvalidQueryException(e.getMessage(), query);
}
}
public void forAccount(final Account.Id id,
final AsyncCallback<AccountDashboardInfo> callback) {
final Account.Id me = getAccountId();
@@ -298,16 +176,6 @@ public class ChangeListServiceImpl extends BaseServiceImplementation implements
});
}
private int safePageSize(final int pageSize) throws InvalidQueryException {
int maxLimit = currentUser.get().getCapabilities()
.getRange(GlobalCapability.QUERY_LIMIT)
.getMax();
if (maxLimit <= 0) {
throw new InvalidQueryException("Search Disabled");
}
return 0 < pageSize && pageSize <= maxLimit ? pageSize : maxLimit;
}
private List<ChangeInfo> filter(final ResultSet<Change> rs,
final Set<Change.Id> starred, final AccountInfoCacheFactory accts,
final ReviewDb db) throws OrmException {
@@ -322,68 +190,4 @@ public class ChangeListServiceImpl extends BaseServiceImplementation implements
}
return r;
}
private abstract class QueryNext implements Action<SingleListChangeInfo> {
protected final String pos;
protected final int limit;
protected final int slim;
QueryNext(final int pageSize, final String pos) throws InvalidQueryException {
this.pos = pos;
this.limit = safePageSize(pageSize);
this.slim = limit + 1;
}
public SingleListChangeInfo run(final ReviewDb db) throws OrmException,
InvalidQueryException {
final AccountInfoCacheFactory ac = accountInfoCacheFactory.create();
final SingleListChangeInfo d = new SingleListChangeInfo();
final Set<Change.Id> starred = currentUser.get().getStarredChanges();
final ArrayList<ChangeInfo> list = new ArrayList<ChangeInfo>();
final ResultSet<Change> rs = query(db, slim, pos);
for (final Change c : rs) {
if (!canRead(c, db)) {
continue;
}
final ChangeInfo ci = new ChangeInfo(c);
ac.want(ci.getOwner());
ci.setStarred(starred.contains(ci.getId()));
list.add(ci);
if (list.size() == slim) {
rs.close();
break;
}
}
final boolean atEnd = finish(list);
d.setChanges(list, atEnd);
d.setAccounts(ac.create());
return d;
}
boolean finish(final ArrayList<ChangeInfo> list) {
final boolean atEnd = list.size() <= limit;
if (list.size() == slim) {
list.remove(limit);
}
return atEnd;
}
abstract ResultSet<Change> query(final ReviewDb db, final int slim,
String sortKey) throws OrmException, InvalidQueryException;
}
private abstract class QueryPrev extends QueryNext {
QueryPrev(int pageSize, String pos) throws InvalidQueryException {
super(pageSize, pos);
}
@Override
boolean finish(final ArrayList<ChangeInfo> list) {
final boolean atEnd = super.finish(list);
Collections.reverse(list);
return atEnd;
}
}
}