Skip to content

Commit

Permalink
Conditionally update post date and read status based on if date is pa…
Browse files Browse the repository at this point in the history
…rsed correctly and it's greater than previous post date
  • Loading branch information
msasikanth committed Feb 27, 2025
1 parent 4ccb9a7 commit c991cd4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,20 @@ class RssRepository(
?: Instant.DISTANT_PAST.toEpochMilliseconds()

feedPayload.posts.forEach { post ->
if (post.date > feedLastCleanUpAtEpochMilli) {
postQueries.upsert(
id = nameBasedUuidOf(post.link).toString(),
sourceId = feedId,
title = post.title,
description = post.description,
imageUrl = post.imageUrl,
date = Instant.fromEpochMilliseconds(post.date),
link = post.link,
commnetsLink = post.commentsLink,
rawContent = post.rawContent
)
}
if (post.date < feedLastCleanUpAtEpochMilli) return@forEach

postQueries.upsert(
id = nameBasedUuidOf(post.link).toString(),
sourceId = feedId,
title = post.title,
description = post.description,
imageUrl = post.imageUrl,
date = Instant.fromEpochMilliseconds(post.date),
link = post.link,
commnetsLink = post.commentsLink,
rawContent = post.rawContent,
isDateParsedCorrectly = post.isDateParsedCorrectly,
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ upsert:
INSERT INTO post(id, sourceId, title, description, rawContent, imageUrl, date, link, commentsLink)
VALUES (:id, :sourceId, :title, :description, :rawContent, :imageUrl, :date, :link, :commnetsLink)
ON CONFLICT(id) DO
UPDATE SET title = excluded.title, description = excluded.description, rawContent = excluded.rawContent, imageUrl = excluded.imageUrl;
UPDATE SET
title = excluded.title,
description = excluded.description,
rawContent = excluded.rawContent,
imageUrl = excluded.imageUrl,
date = CASE WHEN :isDateParsedCorrectly AND date < excluded.date THEN excluded.date ELSE date END,
read = CASE WHEN :isDateParsedCorrectly AND date < excluded.date THEN excluded.read ELSE read END;

count:
SELECT COUNT(DISTINCT post.id) FROM post
Expand Down

0 comments on commit c991cd4

Please sign in to comment.