How can I handle long-running API calls in my Forge App?

Hi, I’m just getting started developing Forge apps and for my first app (after the tutorials), I’m trying to build an Admin page that displays a list of all the filters (so that I can find all the filters that reference a particular field for example).

I have this working in my dev environment where there are only a couple of filters but when I move it to production, where there are thousands of filters, it takes so long to run that my app gets timed out.

The filters API only returns 100 entries at a time so I have to make repeated calls until I get all the records. I’m pretty sure my looping is working because I can force a break out of the loop after a couple trips and it shows me the first 100 x loops filters. As soon as I let it loop past a certain number, I get timed out for taking too long.

Is there another way to approach this? As far as I can see, there is no way to ask the API to only return filters with JQL that match a certain pattern so I have to get them all and look myself.

Thanks for any guidance.

Most of the Atlassian rest api’s support pagination (at least in Cloud). You might want to look at moving the request for the filters to your filters to the frontend (custom UI FTW!) and adding in user pagination.

That said - a scheduled task that looks at the filters for a given JQL and saves the results in the storage might not be a bad idea (you might want to limit it to once a day)

1 Like

Thanks for the reply Daniel,
Yes, I’m using pagination to loop through the API calls. I don’t think it would work to have the user paginate through the list of filters because I want to let them enter a field name and use that to “filter” the filters for matching jql. I wouldn’t want to have them need to page through each set.

The idea of having a background task build the list and use that as my source list had occurred to me but I haven’t really tackled “storage” yet. I’m not quite clear on how I would create a background task either. I have Scriptrunner and I can create a scheduled job there and issue API calls - just not sure how I would integrate it with my app.

I don’t see a lot of examples of using storage (there are two approaches right - storage API and entity properties?) so not really sure how to approach it from that angle.