idz: Un-hardcode result limit in repo layer

Minor design nit but I should probably take my own code review
advice.
This commit is contained in:
Tau 2019-11-30 14:13:49 -05:00
parent e195cf77cd
commit 4db3d94ee8
3 changed files with 8 additions and 6 deletions

View File

@ -18,7 +18,7 @@ export async function loadTopTen(
}
const { routeNo, minTimestamp } = selector;
const src = await w.timeAttack().loadTopTen(routeNo, minTimestamp);
const src = await w.timeAttack().loadTop(routeNo, minTimestamp, 10);
if (src.length === 0) {
continue;

View File

@ -116,9 +116,10 @@ export interface TopTenResult {
}
export interface TimeAttackRepository {
loadTopTen(
loadTop(
routeNo: Model.RouteNo,
minTimestamp: Date
minTimestamp: Date,
limit: number
): Promise<TopTenResult[]>;
loadAll(profileId: Id<Model.Profile>): Promise<Model.TimeAttackScore[]>;

View File

@ -24,9 +24,10 @@ function _extractRow(row: Row): TimeAttackScore {
export class SqlTimeAttackRepository implements TimeAttackRepository {
constructor(private readonly _txn: Transaction) {}
async loadTopTen(
async loadTop(
routeNo: RouteNo,
minTimestamp: Date
minTimestamp: Date,
limit: number
): Promise<TopTenResult[]> {
// We're not using an ORM here so this join-heavy SQL is unfortunately
// going to be a boilerplated mess.
@ -55,7 +56,7 @@ export class SqlTimeAttackRepository implements TimeAttackRepository {
.where("ta.route_no", routeNo)
.where(sql.gt("ta.timestamp", minTimestamp))
.orderBy(["ta.total_time asc", "ta.timestamp asc"])
.limit(10);
.limit(limit);
const rows = await this._txn.fetchRows(loadSql);