This article details how to paginate past the offset:1000 limit that is inherent to query methods like queryChannels and queryUsers. The following examples will use the queryUsers endpoint but can also be applied to queryChannels.
To paginate through a list of users, an offset is provided to the options argument of the queryUsers method...for example
client.queryUsers(
filter,
sort,
{ offset: 10 }
For performance reasons, the offset has a limit of 1,000.
This poses an issue for applications with more than 1,000 users - however there is a way to work around this limit to paginate past the offset limit.
The suggested approach is to add a created_at or last_active property to the filter of queryUsers and update that value once the limit is reached. Then, check for values greater than/less than (depending on the use-case) the given value using $lt or $gt
The idea is that once the offset limit is reached, to replace the created_at or last_active field in the filter with the respective value from the last user returned from the query.
Please also ensure that whatever field being added to the filter is also being sorted in the sort argument of the method - this will ensure that the order of results.
The final query might look something like this...
let last_created_at = "2000-01-01T12:00:00.987918Z"
client.queryUsers(
{ created_at: { $gt: last_created_at },
{ created_at: -1 },
{ offset: 1000 }
)
// when the offset limit is reached, get the created_at value
// from the last user returned in the query and update the value supplied to your filter
Comments
0 comments
Please sign in to leave a comment.