NotionX / react-notion-x

Fast and accurate React renderer for Notion. TS batteries included. ⚡️
https://react-notion-x-demo.transitivebullsh.it
MIT License
4.75k stars 552 forks source link

What is the rate limit of notion-client? #480

Open wildcatco opened 1 year ago

wildcatco commented 1 year ago

Description

I get 'too many requests' response when using getPage method. What is the rate limit of the reqeust?

Notion Test Page ID

addison-codes commented 1 year ago

Just wanted to follow up on this. I am rendering a large database and when deploying to Vercel it fails due to rate limiting.

LesTontonsDev commented 1 year ago

Same issue on our end, really annoying we're not able to update our content with current limitation

hellocory commented 10 months ago

Use redis to cache your data, then only use the redis data. Create a way to update the cache, or set a timer. This allows you to call your data as many times as needed.

Also, if you're calling data via Client, it will always try to make a request. If you're on development, it'll request twice per transaction.

janek commented 5 months ago

I managed to get around this by modifying the package to add a delay and lower the concurrency.

  1. Add a delay
    
    // Add a new function at top level
    function delay(duration) {
    console.log("Delaying... 🕑", duration) // To make sure your module is read locally and not from npm. Comment it out later.
    return new Promise(resolve => setTimeout(resolve, duration));
    }
    (...)

// Then call it from getPage var NotionCompatAPI = class { constructor(client) { this.client = client; } async getPage(rawPageId) { await delay(350);

const pageId = parsePageId(rawPageId);
(...)

2. Lower concurrency

async resolvePage(rootBlockId, { concurrency = 1 // Change this number from 4 to 1 } = {}) {


 While you're in the file you can also disable this console log to make build output more readable:

// console.log("blocks.children.list", { blockId, cursor });



 Most likely using both is an overkill, but I'm just doing it in a safe way at first.

 It would make sense to add a PR to enable this optionally using a parameter in `getPage` call. I don't know if I will do it, but if I do I will link it here.