mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 14:44:05 -08:00
🐛 Fix pagination issue with Slack node (#2328)
* ⚡ Fix pagination in Slack-Node Previously, if you had more than 1k channels, only the first 1k would be loaded. Now with pagination, the limit is ~40k (due to rate limiting, which this doesn't handle well) * 🐛 Fix issue with pagination Continues with #2308 Co-authored-by: Fahrzin Hemmati <fahhem@users.noreply.github.com>
This commit is contained in:
parent
0b1b4baaab
commit
3af223cd8e
|
@ -71,15 +71,21 @@ export async function slackApiRequestAllItems(this: IExecuteFunctions | ILoadOpt
|
||||||
const returnData: IDataObject[] = [];
|
const returnData: IDataObject[] = [];
|
||||||
let responseData;
|
let responseData;
|
||||||
query.page = 1;
|
query.page = 1;
|
||||||
|
//if the endpoint uses legacy pagination use count
|
||||||
|
//https://api.slack.com/docs/pagination#classic
|
||||||
|
if (endpoint.includes('files.list')) {
|
||||||
query.count = 100;
|
query.count = 100;
|
||||||
|
} else {
|
||||||
|
query.limit = 5;
|
||||||
|
}
|
||||||
do {
|
do {
|
||||||
responseData = await slackApiRequest.call(this, method, endpoint, body, query);
|
responseData = await slackApiRequest.call(this, method, endpoint, body, query);
|
||||||
query.cursor = encodeURIComponent(_.get(responseData, 'response_metadata.next_cursor'));
|
query.cursor = _.get(responseData, 'response_metadata.next_cursor');
|
||||||
query.page++;
|
query.page++;
|
||||||
returnData.push.apply(returnData, responseData[propertyName]);
|
returnData.push.apply(returnData, responseData[propertyName]);
|
||||||
} while (
|
} while (
|
||||||
(responseData.response_metadata !== undefined &&
|
(responseData.response_metadata !== undefined &&
|
||||||
responseData.response_metadata.mext_cursor !== undefined &&
|
responseData.response_metadata.next_cursor !== undefined &&
|
||||||
responseData.response_metadata.next_cursor !== '' &&
|
responseData.response_metadata.next_cursor !== '' &&
|
||||||
responseData.response_metadata.next_cursor !== null) ||
|
responseData.response_metadata.next_cursor !== null) ||
|
||||||
(responseData.paging !== undefined &&
|
(responseData.paging !== undefined &&
|
||||||
|
|
Loading…
Reference in a new issue