Search age (aka last updated) with ChangeIndex

The age operator is implemented as a range query on the updated
ChangeField.  To save space the value is represented as the number
of minutes since the epoch, removing about 16 bits from the 64 bit
timestamp.  The field is stored to permit a future change to sort.

Aside from age also send sortkey_before and sortkey_after to the
ChangeIndex.  These drive off the same updated field as age, and
round out the set of operators that support range queries.

With this complete the ChangeIndex can answer many common user
queries without hitting the database. Result sorting still loads
the change records, to be fixed in a future commit.

Change-Id: Ib8056f21d866904122d37241cc52f69a998b30c2
This commit is contained in:
Shawn Pearce
2013-06-25 15:06:38 -06:00
committed by Dave Borowitz
parent 6a7dde6d95
commit 95b77ffdf3
9 changed files with 170 additions and 15 deletions

View File

@@ -24,6 +24,7 @@ import com.google.gwtorm.server.OrmException;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.sql.Timestamp;
import java.util.Map;
/**
@@ -38,7 +39,7 @@ import java.util.Map;
*/
public class ChangeField {
/** Increment whenever making schema changes. */
public static final int SCHEMA_VERSION = 2;
public static final int SCHEMA_VERSION = 3;
/** Legacy change ID. */
public static final FieldDef<ChangeData, Integer> CHANGE_ID =
@@ -95,6 +96,17 @@ public class ChangeField {
}
};
/** Last update time since January 1, 1970. */
public static final FieldDef<ChangeData, Timestamp> UPDATED =
new FieldDef.Single<ChangeData, Timestamp>(
"updated", FieldType.TIMESTAMP, true) {
@Override
public Timestamp get(ChangeData input, FillArgs args)
throws OrmException {
return input.change(args.db).getLastUpdatedOn();
}
};
/** List of filenames modified in the current patch set. */
public static final FieldDef<ChangeData, Iterable<String>> FILE =
new FieldDef.Repeatable<ChangeData, String>(