Skip to content

Commit

Permalink
add a little stagger
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Nov 21, 2024
1 parent f67e5b7 commit ff34e8f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions api/.env.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Required for the random-color-theme API, needs editor role or higher
SANITY_API_WRITE_TOKEN=
6 changes: 5 additions & 1 deletion api/api/random-color-theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ export default async function handler(request: Request) {
})
const _id = 'theme'
const patch = client.patch(_id).set(generateThemeColors())
await client.transaction().createIfNotExists({_id, _type: _id}).patch(patch).commit()
await Promise.allSettled([
client.transaction().createIfNotExists({_id, _type: _id}).patch(patch).commit(),
// Wait 3 seconds to stagger requests a little bit
new Promise((resolve) => setTimeout(resolve, 3_000)),
])

return new Response(JSON.stringify({patch}), {status: 200, headers})
} catch (err) {
Expand Down

0 comments on commit ff34e8f

Please sign in to comment.