Skip to content

Commit

Permalink
fix: increase notifications throttle limit
Browse files Browse the repository at this point in the history
  • Loading branch information
MTG2000 committed Nov 20, 2023
1 parent f1c1706 commit 1c14313
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/handlers/event-message-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>()
const notificationsSentInLastHour = new Set<string>()

async function sendNewCommentNotification(event: Event) {
// const storyUrl = BF_STORY_URL_REGEX.exec(event.content)?.[0]
Expand All @@ -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] ?? ''
Expand All @@ -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`,
Expand All @@ -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)
}
}

Expand Down

0 comments on commit 1c14313

Please sign in to comment.