Skip to content

Commit

Permalink
Merge pull request #14 from dabigjoe6/fix-sync
Browse files Browse the repository at this point in the history
Fix sync process
  • Loading branch information
dabigjoe6 authored Jun 21, 2023
2 parents 55fc132 + 360af4a commit ff4bb4a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/scrapers/Medium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default class Medium {
datePublished,
content,
authorsName,
latest: index === 0,
latest: false,
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/scrapers/RSS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default class RSS {
datePublished,
content,
authorsName,
latest: index === 0,
latest: false,
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/scrapers/Substack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class Substack {
datePublished,
content,
authorsName,
latest: index === 0,
latest: false,
});
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/sync-feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const syncAuthorsResources = async (posts: Array<ResourceI>, authorId: string) =
}


const syncPosts = async (newPosts: ResourceI[], mostRecentPostsInDb: ResourceI[], service: Sources, authorId: string) => {
const syncPosts = async (newPosts: ResourceI[], mostRecentPostsInDb: Array<string>, service: Sources, authorId: string) => {
if (!newPosts) {
console.error(
"newPosts is undefined but required - syncResourcesConsumer"
Expand All @@ -63,6 +63,7 @@ const syncPosts = async (newPosts: ResourceI[], mostRecentPostsInDb: ResourceI[]
...post,
source: service,
author: authorId,
latest: true
}));

console.log("Saving posts to DB");
Expand All @@ -74,11 +75,11 @@ const syncPosts = async (newPosts: ResourceI[], mostRecentPostsInDb: ResourceI[]
// Check for new posts thats does not exist in DB
const newPostsNotInDb: ResourceI[] = [];
const mostRecentPostsMap: {
[key: string]: ResourceI
[key: string]: string
} = {};

mostRecentPostsInDb.forEach((mostRecentPost) => {
mostRecentPostsMap[mostRecentPost.url] = mostRecentPost;
mostRecentPostsMap[mostRecentPost] = mostRecentPost;
});

newPosts.forEach((newPost) => {
Expand All @@ -91,6 +92,7 @@ const syncPosts = async (newPosts: ResourceI[], mostRecentPostsInDb: ResourceI[]
...post,
source: service,
author: authorId,
latest: true
}));

console.log("Saving posts to DB");
Expand Down

0 comments on commit ff4bb4a

Please sign in to comment.