Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GAL-4030] Exclude events for curated feed #1157

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions db/gen/coredb/recommend.sql.go

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

1 change: 1 addition & 0 deletions db/queries/core/recommend.sql
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ from feed_entity_scores f1
where f1.created_at > @window_end::timestamptz
and (@include_viewer::bool or f1.actor_id != @viewer_id)
and (@include_posts::bool or f1.feed_entity_type != @post_entity_type)
and (@include_events::bool or f1.feed_entity_type != @feed_entity_type)
and not (f1.action = any(@excluded_feed_actions::varchar[]))
union
select *
Expand Down
59 changes: 46 additions & 13 deletions publicapi/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,41 @@ func (api FeedAPI) GlobalFeed(ctx context.Context, before *string, after *string
return paginator.paginate(before, after, first, last)
}

type feedParams struct {
ExcludeUserID persist.DBID
IncludePosts bool
IncludeEvents bool
ExcludeActions []persist.Action
FetchFrom time.Duration
}

func fetchFeedEntities(ctx context.Context, queries *db.Queries, p feedParams) ([]db.FeedEntityScore, error) {
var q db.GetFeedEntityScoresParams

q.IncludeViewer = true
q.IncludePosts = true
q.IncludeEvents = true
q.WindowEnd = time.Now().Add(-p.FetchFrom)
q.ExcludedFeedActions = util.MapWithoutError(p.ExcludeActions, func(a persist.Action) string { return string(a) })

if !p.IncludePosts {
q.IncludePosts = false
q.PostEntityType = int32(persist.PostTypeTag)
}

if !p.IncludeEvents {
q.IncludeEvents = false
q.FeedEntityType = int32(persist.FeedEventTypeTag)
}

if p.ExcludeUserID != "" {
q.IncludeViewer = false
q.ViewerID = p.ExcludeUserID
}

return queries.GetFeedEntityScores(ctx, q)
}

func (api FeedAPI) TrendingFeed(ctx context.Context, before *string, after *string, first *int, last *int, includePosts bool) ([]any, PageInfo, error) {
// Validate
if err := validatePaginationParams(api.validator, first, last); err != nil {
Expand All @@ -334,12 +369,11 @@ func (api FeedAPI) TrendingFeed(ctx context.Context, before *string, after *stri

if !hasCursors {
calcFunc := func(ctx context.Context) ([]persist.FeedEntityType, []persist.DBID, error) {
trendData, err := api.queries.GetFeedEntityScores(ctx, db.GetFeedEntityScoresParams{
WindowEnd: time.Now().Add(-time.Duration(3 * 24 * time.Hour)),
PostEntityType: int32(persist.PostTypeTag),
ExcludedFeedActions: []string{string(persist.ActionUserCreated), string(persist.ActionUserFollowedUsers)},
IncludeViewer: true,
IncludePosts: includePosts,
trendData, err := fetchFeedEntities(ctx, api.queries, feedParams{
IncludePosts: includePosts,
IncludeEvents: true,
ExcludeActions: []persist.Action{persist.ActionUserCreated, persist.ActionUserFollowedUsers},
FetchFrom: time.Duration(3 * 24 * time.Hour),
})
if err != nil {
return nil, nil, err
Expand Down Expand Up @@ -438,13 +472,12 @@ func (api FeedAPI) CuratedFeed(ctx context.Context, before, after *string, first
}

if !hasCursors {
trendData, err := api.queries.GetFeedEntityScores(ctx, db.GetFeedEntityScoresParams{
WindowEnd: time.Now().Add(-time.Duration(7 * 24 * time.Hour)),
PostEntityType: int32(persist.PostTypeTag),
ExcludedFeedActions: []string{string(persist.ActionUserCreated), string(persist.ActionUserFollowedUsers)},
IncludeViewer: false,
ViewerID: userID,
IncludePosts: includePosts,
trendData, err := fetchFeedEntities(ctx, api.queries, feedParams{
IncludePosts: includePosts,
IncludeEvents: !includePosts,
ExcludeUserID: userID,
ExcludeActions: []persist.Action{persist.ActionUserCreated, persist.ActionUserFollowedUsers},
FetchFrom: time.Duration(7 * 24 * time.Hour),
})
if err != nil {
return nil, PageInfo{}, err
Expand Down
Loading