Perfomance issues when querying campaigns

Hello,
I built a query to retrieve the data from the Matomo API but I’m having severe performance issues with it.

I am using the Refferers API method “Referrers.getCampaigns” to get the clicks for each campaign (see https://developer.matomo.org/api-reference/reporting-api#Referrers). I am retrieving the data from 4 months for ~2000 siteIds. When I group them into packages of 150 sideIds at once the request takes about 20 seconds. So far, no problem.
These are my parameters:
array:9 [
“period” => “range”
“date” => “2020-03-01,2020-07-01”
“idSite” => “1,2,3,4,5,…,149,150”
“module” => “API”
“method” => “Referrers.getCampaigns”
“format” => “json”
“token_auth” => “…”
“filter_limit” => -1
]

But now, I need to retrieve the clicks for each campaign for a specific pageUrl for each siteId. Therefore, I add a segment to filter the data: “segment” => “pageUrl=@some_string.html”

As soon as I add this segment the matomo api runs into a 504 Gateway Time-out after 60 seconds.
I tried to reduce the siteIds requested at once, down to 10 but even with 10 siteIds at a time, the request takes 40-50 seconds and still runs into a timeout depending on the siteIds in the query. And even if it wouldn’t, 40 seconds for 10 siteIds would mean 1 hour and 20 minutes for the 1200 siteIds I have to fetch the data for.

I’m not sure if this is considered a bug or if there is a much better method to retrieve the exact same data. Any help is highly appreciated.

Thanks in advance, Jan