1
Fork 0

e621: improve page traversal of API results

This commit is contained in:
Conduitry 2020-04-07 21:27:31 -04:00
parent a32f32ca18
commit daa392a48c
1 changed files with 4 additions and 3 deletions

View File

@ -99,12 +99,13 @@ function make_request(path, params) {
// find all posts matching tags, iterating through pages
async function find_all_posts(tags) {
const all_posts = [];
for (let page = 1; ; page++) {
const { posts } = await make_request('/posts.json', { tags, page });
for (let page = null; ;) {
const { posts } = await make_request('/posts.json', { limit: 320, tags, page });
all_posts.push(...posts);
if (posts.length < 75) {
if (posts.length < 320) {
return all_posts.reverse();
}
page = `b${posts[319].id}`;
}
}