From 1c14313daedb381c9f5b82dbab4fe4d61aced57e Mon Sep 17 00:00:00 2001 From: "MTG\\mtg09" <50504183+MTG2000@users.noreply.github.com> Date: Mon, 20 Nov 2023 11:07:50 +0400 Subject: [PATCH] fix: increase notifications throttle limit --- src/handlers/event-message-handler.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/handlers/event-message-handler.ts b/src/handlers/event-message-handler.ts index 1559cac..aa79b2c 100644 --- a/src/handlers/event-message-handler.ts +++ b/src/handlers/event-message-handler.ts @@ -386,7 +386,7 @@ export class EventMessageHandler implements IMessageHandler { const BF_STORY_URL_REGEX = /(?:http|https):\/\/(bolt.fun|deploy-preview-[\d]+--boltfun.netlify.app|boltfun-preview.netlify.app|localhost:3000)\/story\/([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])/m -const notificationsSentInLastMinute = new Set() +const notificationsSentInLastHour = new Set() async function sendNewCommentNotification(event: Event) { // const storyUrl = BF_STORY_URL_REGEX.exec(event.content)?.[0] @@ -396,7 +396,7 @@ async function sendNewCommentNotification(event: Event) { // throw new Error("Event doesn't contain story URL in its content") // } - if (notificationsSentInLastMinute.has(event.id)) return + if (notificationsSentInLastHour.has(event.id)) return const canonical_url = BF_STORY_URL_REGEX.exec( event.tags.find((tag) => tag[0] === 'r')?.[1] ?? '' @@ -419,7 +419,7 @@ async function sendNewCommentNotification(event: Event) { }, } - notificationsSentInLastMinute.add(event.id) + notificationsSentInLastHour.add(event.id) try { const res = await axios.post( `${process.env.BF_QUEUE_SERVICE_URL}/add-job/notifications/new-comment`, @@ -434,13 +434,13 @@ async function sendNewCommentNotification(event: Event) { ) setTimeout(() => { - notificationsSentInLastMinute.delete(event.id) - }, 60 * 1000) + notificationsSentInLastHour.delete(event.id) + }, 60 * 60 * 1000) return res } catch (error) { console.error('Error sending new comment notification', error) - notificationsSentInLastMinute.delete(event.id) + notificationsSentInLastHour.delete(event.id) } }