From d495029527628aa5ebeaa0cfc5177c27defd0fe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E7=9F=A5=E5=90=8D=E3=81=AE=E7=9D=A1=E6=95=99?= =?UTF-8?q?=E9=AB=98=E6=89=8B?= Date: Mon, 24 Apr 2023 22:45:27 +0800 Subject: [PATCH] fix: `limit` field in the filter (#41) --- README.md | 3 ++- src/repositories/event-repository.ts | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 10ffda24..032dd9fa 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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) diff --git a/src/repositories/event-repository.ts b/src/repositories/event-repository.ts index 035d41a3..0db775a1 100644 --- a/src/repositories/event-repository.ts +++ b/src/repositories/event-repository.ts @@ -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[] = [ { @@ -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 } }