Skip to content

Commit

Permalink
Merge pull request #258 from strideynet/kev-change-media-and-video-qu…
Browse files Browse the repository at this point in the history
…ery-to-or

Include video posts in art feeds
  • Loading branch information
strideynet authored Oct 15, 2024
2 parents 30b544e + 8a29c91 commit fb1c66e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 36 deletions.
2 changes: 2 additions & 0 deletions feed/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ func ServiceWithDefaultFeeds(pgxStore *store.PGXStore) *Service {
generatorOpts: generatorOpts{
DisallowedHashtags: defaultDisallowedHashtags,
HasVideo: tristate.True,
HasMedia: tristate.False,
IsNSFW: tristate.True,
},
}))
Expand All @@ -579,6 +580,7 @@ func ServiceWithDefaultFeeds(pgxStore *store.PGXStore) *Service {
generatorOpts: generatorOpts{
DisallowedHashtags: defaultDisallowedHashtags,
HasVideo: tristate.True,
HasMedia: tristate.False,
IsNSFW: tristate.True,
},
}))
Expand Down
13 changes: 9 additions & 4 deletions feed/feed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func TestGenerator(t *testing.T) {
HasMedia: tristate.True,
},
},
expectedPosts: []string{artPost, nsfwArtPost, nsfwLabelledPost},
expectedPosts: []string{artPost, nsfwArtPost, nsfwLabelledPost, artVideoPost, nsfwArtVideoPost},
},
{
name: "nsfw only art",
Expand All @@ -196,13 +196,14 @@ func TestGenerator(t *testing.T) {
HasMedia: tristate.True,
},
},
expectedPosts: []string{nsfwArtPost, nsfwLabelledPost},
expectedPosts: []string{nsfwArtPost, nsfwLabelledPost, nsfwArtVideoPost},
},
{
name: "pinned post",
opts: chronologicalGeneratorOpts{
generatorOpts: generatorOpts{
Hashtags: []string{"placeholder"},
HasMedia: tristate.False,
},
PinnedDIDs: []string{pinnedFurry.DID()},
},
Expand All @@ -214,6 +215,7 @@ func TestGenerator(t *testing.T) {
generatorOpts: generatorOpts{
Hashtags: []string{},
HasVideo: tristate.True,
HasMedia: tristate.False,
},
},
expectedPosts: []string{videoPost, nsfwVideoPost, artVideoPost, nsfwArtVideoPost},
Expand All @@ -224,6 +226,7 @@ func TestGenerator(t *testing.T) {
generatorOpts: generatorOpts{
IsNSFW: tristate.True,
HasVideo: tristate.True,
HasMedia: tristate.False,
},
},
expectedPosts: []string{nsfwVideoPost, nsfwArtVideoPost},
Expand Down Expand Up @@ -315,7 +318,7 @@ func TestGenerator(t *testing.T) {
HasMedia: tristate.True,
},
},
expectedPosts: []string{artPost, nsfwArtPost, nsfwLabelledPost},
expectedPosts: []string{artPost, nsfwArtPost, nsfwLabelledPost, artVideoPost, nsfwArtVideoPost},
},
{
name: "nsfw only art",
Expand All @@ -327,7 +330,7 @@ func TestGenerator(t *testing.T) {
HasMedia: tristate.True,
},
},
expectedPosts: []string{nsfwArtPost, nsfwLabelledPost},
expectedPosts: []string{nsfwArtPost, nsfwLabelledPost, nsfwArtVideoPost},
},
{
name: "all videos",
Expand All @@ -336,6 +339,7 @@ func TestGenerator(t *testing.T) {
generatorOpts: generatorOpts{
Hashtags: []string{},
HasVideo: tristate.True,
HasMedia: tristate.False,
},
},
expectedPosts: []string{videoPost, nsfwVideoPost, artVideoPost, nsfwArtVideoPost},
Expand All @@ -348,6 +352,7 @@ func TestGenerator(t *testing.T) {
Hashtags: []string{},
IsNSFW: tristate.True,
HasVideo: tristate.True,
HasMedia: tristate.False,
},
},
expectedPosts: []string{nsfwVideoPost, nsfwArtVideoPost},
Expand Down
36 changes: 20 additions & 16 deletions store/gen/candidate_posts.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 20 additions & 16 deletions store/queries/candidate_posts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,17 @@ WHERE
COALESCE(sqlc.narg(disallowed_hashtags)::TEXT [], '{}') = '{}'
OR NOT sqlc.narg(disallowed_hashtags)::TEXT [] && cp.hashtags
)
-- Match has_media status. If unspecified, do not filter.
AND (
sqlc.narg(has_media)::BOOLEAN IS NULL
OR COALESCE(cp.has_media, FALSE) = sqlc.narg(has_media)
)
-- Match has_video status. If unspecified, do not filter.
AND (
sqlc.narg(has_video)::BOOLEAN IS NULL
OR COALESCE(cp.has_video, FALSE) = sqlc.narg(has_video)
-- Match has_media status. If unspecified, do not filter.
(
sqlc.narg(has_media)::BOOLEAN IS NULL
OR COALESCE(cp.has_media, FALSE) = sqlc.narg(has_media)
)
-- Match has_video status. If unspecified, do not filter.
OR (
sqlc.narg(has_video)::BOOLEAN IS NULL
OR COALESCE(cp.has_video, FALSE) = sqlc.narg(has_video)
)
)
-- Filter by NSFW status. If unspecified, do not filter.
AND (
Expand Down Expand Up @@ -109,15 +111,17 @@ WHERE
COALESCE(sqlc.narg(disallowed_hashtags)::TEXT [], '{}') = '{}'
OR NOT sqlc.narg(disallowed_hashtags)::TEXT [] && cp.hashtags
)
-- Match has_media status. If unspecified, do not filter.
AND (
sqlc.narg(has_media)::BOOLEAN IS NULL
OR COALESCE(cp.has_media, FALSE) = sqlc.narg(has_media)
)
-- Match has_video status. If unspecified, do not filter.
AND (
sqlc.narg(has_video)::BOOLEAN IS NULL
OR COALESCE(cp.has_video, FALSE) = sqlc.narg(has_video)
-- Match has_media status. If unspecified, do not filter.
(
sqlc.narg(has_media)::BOOLEAN IS NULL
OR COALESCE(cp.has_media, FALSE) = sqlc.narg(has_media)
)
-- Match has_video status. If unspecified, do not filter.
OR (
sqlc.narg(has_video)::BOOLEAN IS NULL
OR COALESCE(cp.has_video, FALSE) = sqlc.narg(has_video)
)
)
-- Filter by NSFW status. If unspecified, do not filter.
AND (
Expand Down

0 comments on commit fb1c66e

Please sign in to comment.