Skip to content

Commit

Permalink
display total fetched count
Browse files Browse the repository at this point in the history
  • Loading branch information
marcustyphoon committed Sep 9, 2024
1 parent db19915 commit 18ac99e
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/features/mass_privater.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,26 +192,24 @@ const privatePosts = async ({ uuid, name, tags, before }) => {
]
});

const allPostIdsSet = new Set();
let fetchedPosts = 0;
const filteredPostIdsSet = new Set();

const collect = async resource => {
while (resource) {
await Promise.all([
apiFetch(resource).then(({ response }) => {
const posts = response.posts
response.posts
.filter(({ canEdit }) => canEdit === true)
.filter(({ state }) => state === 'published');

posts.forEach(({ id }) => allPostIdsSet.add(id));

posts
.filter(({ state }) => state === 'published')
.filter(({ timestamp }) => timestamp < before)
.forEach(({ id }) => filteredPostIdsSet.add(id));

fetchedPosts += response.posts.length;

resource = response.links?.next?.href;

gatherStatus.textContent = `Found ${filteredPostIdsSet.size} posts (checked ${allPostIdsSet.size})${resource ? '...' : '.'}`;
gatherStatus.textContent = `Found ${filteredPostIdsSet.size} posts (checked ${fetchedPosts})${resource ? '...' : '.'}`;
}),
sleep(1000)
]);
Expand Down

0 comments on commit 18ac99e

Please sign in to comment.