From 424b5eaf50dda079eae00ae93b7cba208125ff9d Mon Sep 17 00:00:00 2001 From: Sasikanth Miriyampalli Date: Thu, 8 Feb 2024 16:15:41 +0530 Subject: [PATCH] Update posts count query to support posts type config (#303) Since we have support for showing different posts type in home screen - All - Unread only - Today We are updating the count query to support them, similar to how we do when getting the posts. --- .../rss/reader/repository/RssRepository.kt | 4 +++- .../dev/sasikanth/rss/reader/database/Post.sq | 23 +++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/repository/RssRepository.kt b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/repository/RssRepository.kt index 9aabb8f85..9df2247c1 100644 --- a/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/repository/RssRepository.kt +++ b/shared/src/commonMain/kotlin/dev/sasikanth/rss/reader/repository/RssRepository.kt @@ -175,7 +175,9 @@ class RssRepository( countQuery = postQueries.count( feedLink = selectedFeedLink, - featuredPostsLimit = NUMBER_OF_FEATURED_POSTS + featuredPostsLimit = NUMBER_OF_FEATURED_POSTS, + unreadOnly = unreadOnly, + postsAfter = after, ), transacter = postQueries, context = ioDispatcher, diff --git a/shared/src/commonMain/sqldelight/dev/sasikanth/rss/reader/database/Post.sq b/shared/src/commonMain/sqldelight/dev/sasikanth/rss/reader/database/Post.sq index 4cabc5ee2..0e985783c 100644 --- a/shared/src/commonMain/sqldelight/dev/sasikanth/rss/reader/database/Post.sq +++ b/shared/src/commonMain/sqldelight/dev/sasikanth/rss/reader/database/Post.sq @@ -25,11 +25,22 @@ UPDATE SET title = excluded.title, description = excluded.description, rawConten count: SELECT COUNT(*) FROM post -WHERE (:feedLink IS NULL OR post.feedLink = :feedLink) AND post.link NOT IN ( - SELECT post.link FROM post - WHERE (:feedLink IS NULL OR post.feedLink = :feedLink) AND post.imageUrl IS NOT NULL - ORDER BY post.date DESC LIMIT :featuredPostsLimit -); +WHERE + (:unreadOnly IS NULL OR post.read != :unreadOnly) AND + (:feedLink IS NULL OR post.feedLink = :feedLink) AND + -- Skip featured posts -- + post.link NOT IN ( + SELECT post.link FROM post + WHERE + (:unreadOnly IS NULL OR post.read != :unreadOnly) AND + (:feedLink IS NULL OR post.feedLink = :feedLink) AND + post.imageUrl IS NOT NULL AND + post.date > :postsAfter + ORDER BY post.date DESC LIMIT :featuredPostsLimit + ) AND + -- Skip featured posts -- + post.date > :postsAfter +ORDER BY post.date DESC; featuredPosts: SELECT @@ -71,6 +82,7 @@ INNER JOIN feed ON post.feedLink == feed.link WHERE (:unreadOnly IS NULL OR post.read != :unreadOnly) AND (:feedLink IS NULL OR post.feedLink = :feedLink) AND + -- Skip featured posts -- post.link NOT IN ( SELECT post.link FROM post WHERE @@ -80,6 +92,7 @@ WHERE post.date > :postsAfter ORDER BY post.date DESC LIMIT :featuredPostsLimit ) AND + -- Skip featured posts -- post.date > :postsAfter ORDER BY post.date DESC LIMIT :limit OFFSET :offset;