Accounting for indexed posts.

This commit is contained in:
2018-06-30 21:47:43 +02:00
parent 74e36a6826
commit a859ac573c
4 changed files with 13 additions and 14 deletions

View File

@@ -25,8 +25,8 @@ function curatePost(acc, post, user, index, processed, args) {
hash: hashPost(post),
};
if (user.indexed.find(entry => entry.id === post.id)) {
return { ...acc, indexed: { ...acc.indexed, [post.id]: curatedPost } };
if (user.indexed.original.find(entry => entry.id === post.id)) {
return { ...acc, indexedUpdated: [...acc.indexedUpdated, curatedPost] };
}
// cut-off at limit, but don't count posts requested directly by ID
@@ -73,16 +73,16 @@ function curatePost(acc, post, user, index, processed, args) {
const curatePosts = (userPosts, args) => Object.values(userPosts).reduce((accPosts, user) => {
const processed = new Set();
const { posts, indexed } = user.posts.reduce((accUserPosts, post, index) =>
curatePost(accUserPosts, post, user, index, processed, args), { posts: [], indexed: {} });
const { posts, indexedUpdated } = user.posts.reduce((accUserPosts, post, index) =>
curatePost(accUserPosts, post, user, index, processed, args), { posts: [], indexedUpdated: [] });
const indexedLength = Object.keys(indexed).length;
if (indexedLength > 0) {
console.log('\x1b[33m%s\x1b[0m', `Ignoring ${indexedLength} indexed posts for '${user.name}'`);
if (indexedUpdated.length > 0) {
console.log('\x1b[33m%s\x1b[0m', `Ignoring ${indexedUpdated.length} indexed posts for '${user.name}'`);
}
return { ...accPosts, [user.name]: { ...user, posts } };
const indexedOriginal = user.indexed.original.filter(entry => !indexedUpdated.find(post => post.id === entry.id));
return { ...accPosts, [user.name]: { ...user, posts, indexed: { original: indexedOriginal, updated: indexedUpdated } } };
}, {});
module.exports = curatePosts;