query: Fix limit:N clauses on strange iterators

If the underlying source didn't abort at the result limit count we
have to clip it manually ourselves higher up in the query processor.
I failed to use the limit:N value and instead clipped with the
default, resulting in larger result sets for certain queries.

Change-Id: Ibc68dde8631788ffa1e2ea23266bb736280abc04
Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce 2010-07-19 18:06:26 -07:00
parent 5b437cc7a0
commit 660c71038b
2 changed files with 12 additions and 2 deletions

View File

@ -412,6 +412,11 @@ public class ChangeQueryBuilder extends QueryBuilder<ChangeData> {
return find(p, IntPredicate.class, FIELD_LIMIT) != null;
}
@SuppressWarnings("unchecked")
public int getLimit(Predicate<ChangeData> p) {
return ((IntPredicate) find(p, IntPredicate.class, FIELD_LIMIT)).intValue();
}
@SuppressWarnings("unchecked")
public boolean hasSortKey(Predicate<ChangeData> p) {
return find(p, SortKeyPredicate.class, "sortkey_after") != null

View File

@ -140,8 +140,9 @@ public class QueryProcessor {
}
});
if (defaultLimit < results.size()) {
results = results.subList(0, defaultLimit);
int limit = limit(s);
if (limit < results.size()) {
results = results.subList(0, limit);
}
for (ChangeData d : results) {
@ -190,6 +191,10 @@ public class QueryProcessor {
}
}
private int limit(Predicate<ChangeData> s) {
return queryBuilder.hasLimit(s) ? queryBuilder.getLimit(s) : defaultLimit;
}
@SuppressWarnings("unchecked")
private Predicate<ChangeData> compileQuery(String queryString,
final Predicate<ChangeData> visibleToMe) throws QueryParseException {