fix: avoid excessive supabase requests to prevent rate limit (#3250)
This is related to #3240, but likely does not fix the crash.
#3240 mentions heavy rate-limits from Supabase. This happens because
currently:
- we are polling the Supabase endpoint every 5 seconds, and
- we do not stop making requests when we get rate limited.
This PR makes a few changes:
1. When we get rate-limited by Supabase, we'll check the `Retry-After`
property that Supabase sends back. This tells us when Supabase will
allow us to make our next request, and we'll honor that value.
2. Changes the polling rate from once every 5 seconds to once every 15
seconds. From what I can tell the requests are just fetching logs from
the Supabase API, so I don't think that it's critical enough to need to
happen once every 5 seconds. If I'm wrong about this though, please
correct me.
3. Refactors `loadEdgeLogsMutation` into a `useQuery` call, which is
probably what we want it to be given that we're periodically polling an
API endpoint. The side effects can be handled in a separate `useEffect`
call, so the behavior should stay essentially the same. This does also
prevent us from making extra requests to the endpoint when we already
have an active request.
Also closes #3244.
<!-- devin-review-badge-begin -->
---
<a href="https://app.devin.ai/review/dyad-sh/dyad/pull/3250"
target="_blank">
<picture>
<source media="(prefers-color-scheme: dark)"
srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1">
<img
src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1"
alt="Open in Devin Review">
</picture>
</a>
<!-- devin-review-badge-end -->
正在显示
请
注册
或者
登录
后发表评论