Skip to content

Commit

Permalink
fix: limit field in the filter (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
flxxyz authored Apr 24, 2023
1 parent b9d0298 commit d495029
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ NIPs with a relay-specific implementation are listed here.
- [x] NIP-26: Delegated Event Signing
- [x] NIP-28: Public Chat
- [x] NIP-33: Parameterized Replaceable Events
- [x] NIP-38: [Encrypted Group Chat with Megolm group ratchet (Draft)](https://oi5l5umbjx.feishu.cn/docx/TW7Ndb6Imoj3n7x08MTcleqanad)
- [x] NIP-40: Expiration Timestamp

## Architecture
Expand All @@ -64,7 +65,7 @@ Todo

## Requirements

- Deno v1.30.x or later
- Deno v1.30.x or v1.31.x
- Typescript
- MongoDB 4.4, 5.0, 6.0
- Redis (Optional)
Expand Down
10 changes: 7 additions & 3 deletions src/repositories/event-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class EventRepository implements IEventRepository {
const $or: any[] = []
const $sort = { event_created_at: 1 }
const limit = {
$limit: 500,
$limit: 1000,
}
const pipelines: any[] = [
{
Expand Down Expand Up @@ -78,8 +78,12 @@ export class EventRepository implements IEventRepository {
subFilter['event_created_at'] = { $lte: filterValue }
}

if (filterName === 'limit' && typeof filterValue === 'number') {
limit.$limit = filterValue
if (filterName === 'limit' && typeof filterValue === 'number' && filterValue > 0) {
if (filterValue >= 5000) {
limit.$limit = 5000
} else {
limit.$limit = filterValue
}
$sort.event_created_at = -1
}
}
Expand Down

0 comments on commit d495029

Please sign in to comment.