Skip to content

Commit

Permalink
fix: Remove setInterval
Browse files Browse the repository at this point in the history
  • Loading branch information
storm1729 committed Jan 16, 2024
1 parent 36ea7a4 commit f752f58
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/app/[lang]/dashboard/ApiUsage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,9 @@ export function ApiUsage({
const [apiCalls, setApiCalls] = useState<number | undefined>(undefined); // undefined means loading

useEffect(() => {
const t = setInterval(() => {
getApiUsage(supabase, subscription)
.then(setApiCalls)
.catch(sentryException);
}, 3000);

return () => clearInterval(t);
getApiUsage(supabase, subscription)
.then(setApiCalls)
.catch(sentryException);
}, [supabase, subscription]);

return (
Expand Down
13 changes: 13 additions & 0 deletions supabase/migrations/20240116132530_get_api_usage.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
CREATE OR REPLACE FUNCTION get_user_calls_count(created_at_param timestamptz)
RETURNS INTEGER AS $$
DECLARE
calls_count INTEGER;
BEGIN
SELECT COUNT(*)
INTO calls_count
FROM calls
WHERE created_at >= created_at_param;

RETURN calls_count;
END;
$$ LANGUAGE plpgsql;

1 comment on commit f752f58

@vercel
Copy link

@vercel vercel bot commented on f752f58 Jan 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.