Added a limit to the number of items on the landing page following tab

This commit is contained in:
Asaf Gartner 2024-07-06 12:52:50 +03:00
parent 0497b262f4
commit 1163640121
3 changed files with 22 additions and 3 deletions

View File

@ -16,7 +16,12 @@ func FollowingTest(c *RequestContext) ResponseData {
lineageBuilder := models.MakeSubforumLineageBuilder(subforumTree) lineageBuilder := models.MakeSubforumLineageBuilder(subforumTree)
c.Perf.EndBlock() c.Perf.EndBlock()
timelineItems, err := FetchFollowTimelineForUser(c, c.Conn, c.CurrentUser, lineageBuilder) timelineItems, err := FetchFollowTimelineForUser(
c, c.Conn,
c.CurrentUser,
lineageBuilder,
FollowTimelineQuery{},
)
if err != nil { if err != nil {
return c.ErrorResponse(http.StatusInternalServerError, err) return c.ErrorResponse(http.StatusInternalServerError, err)
} }

View File

@ -52,7 +52,14 @@ func Index(c *RequestContext) ResponseData {
var newsItems []templates.TimelineItem var newsItems []templates.TimelineItem
if c.CurrentUser != nil { if c.CurrentUser != nil {
followingItems, err = FetchFollowTimelineForUser(c, c.Conn, c.CurrentUser, lineageBuilder) followingItems, err = FetchFollowTimelineForUser(
c, c.Conn,
c.CurrentUser,
lineageBuilder,
FollowTimelineQuery{
Limit: 100,
},
)
if err != nil { if err != nil {
c.Logger.Warn().Err(err).Msg("failed to fetch following feed") c.Logger.Warn().Err(err).Msg("failed to fetch following feed")
} }

View File

@ -20,7 +20,12 @@ import (
"git.handmade.network/hmn/hmn/src/templates" "git.handmade.network/hmn/hmn/src/templates"
) )
func FetchFollowTimelineForUser(ctx context.Context, conn db.ConnOrTx, user *models.User, lineageBuilder *models.SubforumLineageBuilder) ([]templates.TimelineItem, error) { type FollowTimelineQuery struct {
Offset int
Limit int
}
func FetchFollowTimelineForUser(ctx context.Context, conn db.ConnOrTx, user *models.User, lineageBuilder *models.SubforumLineageBuilder, q FollowTimelineQuery) ([]templates.TimelineItem, error) {
perf := perf.ExtractPerf(ctx) perf := perf.ExtractPerf(ctx)
perf.StartBlock("FOLLOW", "Assemble follow data") perf.StartBlock("FOLLOW", "Assemble follow data")
@ -50,6 +55,8 @@ func FetchFollowTimelineForUser(ctx context.Context, conn db.ConnOrTx, user *mod
timelineItems, err = FetchTimeline(ctx, conn, user, lineageBuilder, hmndata.TimelineQuery{ timelineItems, err = FetchTimeline(ctx, conn, user, lineageBuilder, hmndata.TimelineQuery{
OwnerIDs: userIDs, OwnerIDs: userIDs,
ProjectIDs: projectIDs, ProjectIDs: projectIDs,
Offset: q.Offset,
Limit: q.Limit,
}) })
} }
perf.EndBlock() perf.EndBlock()