Reading index file and ignoring already indexed content.

This commit is contained in:
2018-06-17 03:39:12 +02:00
parent 7cf1a99915
commit 33ef3d2c19
5 changed files with 44 additions and 18 deletions

View File

@@ -60,16 +60,18 @@ function curatePost(accUserPosts, post, user, index, processed, args) {
subreddit: post.subreddit.display_name,
preview: post.preview ? post.preview.images.map(image => image.source) : null,
host,
hash: hashPost(post)
hash: hashPost(post),
});
}
const curatePosts = (userPosts, args) => {
const processed = new Set();
const curatePosts = (userPosts, args) => Object.values(userPosts).reduce((accPosts, user) => {
const indexedHostIds = user.indexed.map(entry => entry.hostId); // already downloaded
const processed = new Set(indexedHostIds);
return Object.values(userPosts).reduce((accPosts, user) => {
return { ...accPosts, [user.name]: { ...user, posts: user.posts.reduce((accUserPosts, post, index) => curatePost(accUserPosts, post, user, index, processed, args), []) } };
}, {});
};
const posts = user.posts.reduce((accUserPosts, post, index) =>
curatePost(accUserPosts, post, user, index, processed, args), []);
return { ...accPosts, [user.name]: { ...user, posts } };
}, {});
module.exports = curatePosts;