Skip to content

Commit

Permalink
feat(sqlite): add maximum limit constraint for limit
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyTseng committed Jan 30, 2024
1 parent 41061e0 commit 3c7cd81
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/event-repository-sqlite/src/event-repository-sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class EventRepositorySqlite extends EventRepository {
}

async find(filter: Filter): Promise<Event[]> {
const { ids, authors, kinds, since, until, limit = 1000 } = filter;
const { ids, authors, kinds, since, until, limit } = filter;

if (limit === 0) return [];

Expand Down Expand Up @@ -163,7 +163,7 @@ export class EventRepositorySqlite extends EventRepository {
' ',
)} ${whereClause} ORDER BY e.created_at DESC LIMIT ?`,
)
.all(whereValues.concat(limit));
.all(whereValues.concat(this.applyLimit(limit)));

return rows.map(this.toEvent);
}
Expand All @@ -172,7 +172,7 @@ export class EventRepositorySqlite extends EventRepository {
filter: Filter,
genericTags: string[][],
): Promise<Event[]> {
const { authors, kinds, since, until, limit = 1000 } = filter;
const { authors, kinds, since, until, limit } = filter;

const innerJoinClauses: string[] = [];

Expand Down Expand Up @@ -224,7 +224,7 @@ export class EventRepositorySqlite extends EventRepository {
' ',
)} ${whereClause} ORDER BY g.created_at DESC LIMIT ?) ORDER BY created_at DESC`,
)
.all(whereValues.concat(limit));
.all(whereValues.concat(this.applyLimit(limit)));

return rows.map(this.toEvent);
}
Expand Down Expand Up @@ -269,6 +269,10 @@ export class EventRepositorySqlite extends EventRepository {
.sort((a, b) => a.length - b.length);
}

private applyLimit(limit = 100) {

Check warning on line 272 in packages/event-repository-sqlite/src/event-repository-sqlite.ts

View workflow job for this annotation

GitHub Actions / ci (18.x)

Missing return type on function

Check warning on line 272 in packages/event-repository-sqlite/src/event-repository-sqlite.ts

View workflow job for this annotation

GitHub Actions / ci (20.x)

Missing return type on function

Check warning on line 272 in packages/event-repository-sqlite/src/event-repository-sqlite.ts

View workflow job for this annotation

GitHub Actions / ci (21.x)

Missing return type on function
return Math.min(limit, 1000);
}

private migrate(): {
lastMigration: string | undefined;
executedMigrations: string[];
Expand Down

0 comments on commit 3c7cd81

Please sign in to comment.