Skip to content

Commit

Permalink
🔒 Make sure we don't infinitely call recursive loop
Browse files Browse the repository at this point in the history
  • Loading branch information
foysalit committed Sep 11, 2024
1 parent 9ec0d7e commit 448ceae
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/reports/page-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ const getQueueItems = async (
labelerAgent: Agent,
queryParams: ToolsOzoneModerationQueryStatuses.QueryParams,
queueName: string | null,
attempt = 0,
) => {
const pageSize = 50
const { data } = await labelerAgent.tools.ozone.moderation.queryStatuses({
Expand All @@ -391,14 +392,16 @@ const getQueueItems = async (

// This is a recursive call to get items in queue if the current page
// gives us less than full page size and there are more items to fetch
if (statusesInQueue.length === 0 && data.cursor) {
// also, use a circuit breaker to make sure we never accidentally call this more than 10 times
if (statusesInQueue.length === 0 && data.cursor && attempt < 10) {
return getQueueItems(
labelerAgent,
{
...queryParams,
cursor: data.cursor,
},
queueName,
++attempt,
)
}

Expand Down

0 comments on commit 448ceae

Please sign in to comment.