Building user posts object after fetching user to ensure user fetched posts and directly fetched posts are added to the same user key. Refactor to make better use of functions. Moved profile detail saving call to content fetch. No longer attempting and failing to save profile details for deleted users (directory would not exist).

This commit is contained in:
2018-06-17 01:11:10 +02:00
parent 3b5d886da3
commit 7cf1a99915
11 changed files with 199 additions and 157 deletions

View File

@@ -5,12 +5,12 @@ const config = require('config');
const archives = require('./archives.js');
function getArchivePostIds(username, exclude) {
console.log('Searching archives for posts...');
console.log(`Finding archived posts for '${username}'...`);
return Promise.all(config.fetch.archives.reddit.map(source => archives[source](username))).then(postIds => postIds.flatten()).then(postIds => {
return exclude ? postIds.filter(postId => !exclude.includes(postId)) : postIds;
}).then(postIds => {
console.log(`Found ${postIds.length} unique archived posts`);
console.log(`Found ${postIds.length} unique archived posts for user '${username}'`);
return postIds;
});