Replies: 2 comments
|
You should take a look at the performance improvement tips in this guide https://supabase.com/docs/guides/database/postgres/row-level-security#call-functions-with-select |
|
Nice debugging on this one — the WHERE customer = (select auth.uid())::textThat hoists it into an initPlan that runs once per statement, and the wrapper can then do the direct lookup. It's the same pattern that matters on regular RLS policies too — on an indexed column Supabase measured a filter go from ~179ms to ~9ms just from the I put together the full breakdown with the query plans here: https://www.guardlayer.io/blog/supabase-rls-performance |
Uh oh!
There was an error while loading. Please reload this page.
I have the following set of views defined on top of the Stripe wrapper:
I have defined a function to query it for the current authenticated user like so:
But it was EXTREMELY slow. When I went into the Stripe logs, I noticed it loads ALL the subscription (which required a lot of API calls due to pagination) rather than look up the subscription by the customer id. But if I hard coded a user id instead of using
auth.uid()::text, it properly looked it up by the ID.I then rewrote it to the following, which worked much faster by performing a Stripe lookup by the ID rather than loading all subscriptions:
Is this expected behavior / side effect of using
auth.uid(), or a bug? This seems similar (but not exactly the same) as this issue: https://github.com/orgs/supabase/discussions/8733All reactions