Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

Error 429 on getCompendiumPage

1673057375
Jiboux
Pro
Sheet Author
Compendium Curator
Hello, I am working on compendium integration, and hen dropping an NPC on the VTT, in order to be able to fill in all his abilities, I have to lookup some details of these abilities in the compendium. So during the drop of the Category NPC page, I have a bunch of getcompendiumpage() firing to go and fetch all the data of all its abilities. For high level character it is maybe 30-40 instances firing up one behind the other in a for loop. For low level characters where there is maybe half that much, all works well, but for high level characters, some ability don't actually fill in, and I have in console a bunch of error messages like below that do correspond to each of the instances that didn't fill in. The abilities that don't fill are somehow different from one time to another, but tend to be at the end of the list 1-Does my hypothesis make sense that the simultaneous lookup in the compendium could be somehow flooding the database ? 2-Do you see anyway to avoid the situation while still looking up each ? (Code a bit too complex to get really extracts)
1673077885
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
It likely is that you are making too many calls to the compendium in rapid succession. That error code means that the server is rejecting the request with the current protocol. I'd guess that the back end is setup to return this error when there's too many queued requests from a given requestor. 30 - 40 requests is an extremely large number, and would likely cause perfomance issues for all roll20 users if used in a live character sheet/compendium as there might be several hundred to several thousand of those groups of requests coming in at any given time for a popular game. There are several other problems with this approach: getCompendiumPage  is an asynchronous function and so should not be run in a for loop. You can't ever be sure in what order the various calls will return. You can't centralize any setAttrs that are needed in a single setAttrs getCompendiumPage  is meant to get a single page's info. To handle looking up several pieces of info at once from the compendium, there is the getCompendiumQuery   function which allows you to get several pages at once. So, combining both of those issues gives the solution. Use a getCompendiumQuery call to search the compendium. This then allows you to do your entire search with a single call to the compendium. If you need to then get additional information based on those returned results, you can use a burndown (aka queue) pattern to recursively iterate over the results and construct additional query calls.
1673100489
Jiboux
Pro
Sheet Author
Compendium Curator
Thanks a lot Scott, This is what I was expecting, but I didn't know about getColmpendiumQuery... I'll make some tests, but I see it is in the charactermancer documentation... My issue is not in the charactermancer (I don't have one), but with the sheetworker. This is something that happens when a GM drops an NPC, and the sheet has to "rebuild" the NPC as a character (in any of the NPC pages, there is all the data of powers / abilities that are unique to this NPC, but anything that is "standard" there is just the name and rank, and the system has to cross check with the rest of the compendium). Do you know (if you don't, I'll make the test later) if getcompendiumquery is available as a sheetworker function like getcompendiumpage ?
1673101206
Jiboux
Pro
Sheet Author
Compendium Curator
Other short question : I see getcompendiumquery does accept queries, but also arrays of query that I suppose returns an array of results... I do suppose that it is better to do: let QueryArray = [...] getCompendiumQuery(QueryArray, ResultArray={ for() Dosomething(ResultArray(i)) }) Than let QueryArray = [...] for() getCompendiumPage(QueryArray[i], Result =>{  Dosomething(Result) })
1673103077
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Yes, getCompendiumQuery works outside of Charmander. I believe the only Charmander functions that don't are the ones that interact with the mancer pages. And, yes, option one is what you want to do. You can see this technique in action in the official SWADE, Storypath, Genefunk, and Blade Runner sheets.
1673110748
Jiboux
Pro
Sheet Author
Compendium Curator
OK, I have some rewrite to do, but thanks a lot Scott... I will end having finally a compendium !! (working on it since 1 year, nearly done! This is certainly my last sticky point, but this is more for the second expansion )