supabase / wrappers

Postgres Foreign Data Wrapper development framework in Rust.
https://supabase.github.io/wrappers/
Apache License 2.0
469 stars 47 forks source link

Stripe Wrapper Rate Limit? #234

Open LeakedDave opened 5 months ago

LeakedDave commented 5 months ago

I set up the Stripe wrapper then created a database view for my stripe products. I'm loading the products on getServerSideProps. It does work, until I refresh the page 4 times fast, then all data from the foreign table returns empty for an arbitrary amount of time. Are there rate limits to the Stripe Wrapper? Should I not be querying a view to a foreign Stripe table in realtime? I'm thinking I need to pull the entire thing and just use Stripe's API directly for listing products. Their API docs say they support 100 requests per second, but the wrapper can't even do 4...

create view
  public.stripe_products as
select
  products.id,
  products.name,
  products.active,
  products.default_price,
  products.description,
  products.created,
  products.updated,
  products.attrs,
  products.attrs -> 'metadata'::text as metadata
from
  stripe.products;

Using service role server side:

    const { data: products, error } = await supabaseAdmin.from('stripe_products').select('*').limit(3)
    const { data: prices } = await supabaseAdmin.from('stripe_prices').select('*').order('unit_amount').limit(3)

I'm thinking of using a materialized view? But only for products listings... For customer data it needs to be realtime I think. But at that point I may as well just use getStaticProps, fetch the data from their API, and then re-deploy when I make changes to my subscription pricing.

LeakedDave commented 5 months ago
    const supabase = createAdminClient()

    for (let i = 0; i < 10; i++) {
        const { data: products, error } = await supabase.from('stripe_products').select('*').limit(3)
        console.log(`Fetch ${i}: `, products?.length)
        console.log(error)
    }

Output:

Fetch 0:  1
null
Fetch 1:  1
null
Fetch 2:  1
null
Fetch 3:  1
null
Fetch 4:  1
null
Fetch 5:  1
null
Fetch 6:  0
null
Fetch 7:  0
null
Fetch 8:  0
null
Fetch 9:  0
null
vincenzon commented 4 months ago

I see random empty results as well:

https://github.com/supabase/wrappers/issues/237

I can't correlate when the empty results to a rate limit, but I didn't try as thoroughly as you.

I was told by supabase support to use pg_cron to build what is in effect a materialized view of the stripe data in supabase to work around this. That seems like something that should be documented if it is the official workflow.

vincenzon commented 4 months ago

@LeakedDave you might want to checkout the solution here:

https://github.com/supabase/wrappers/issues/237