From 1163640121cc04b84b5f89ae9052b43c1dc60401 Mon Sep 17 00:00:00 2001 From: Asaf Gartner Date: Sat, 6 Jul 2024 12:52:50 +0300 Subject: [PATCH] Added a limit to the number of items on the landing page following tab --- src/website/following.go | 7 ++++++- src/website/landing.go | 9 ++++++++- src/website/timeline_helper.go | 9 ++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/website/following.go b/src/website/following.go index e7205328..3700bfa5 100644 --- a/src/website/following.go +++ b/src/website/following.go @@ -16,7 +16,12 @@ func FollowingTest(c *RequestContext) ResponseData { lineageBuilder := models.MakeSubforumLineageBuilder(subforumTree) 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 { return c.ErrorResponse(http.StatusInternalServerError, err) } diff --git a/src/website/landing.go b/src/website/landing.go index 4cfc0f38..922aef02 100644 --- a/src/website/landing.go +++ b/src/website/landing.go @@ -52,7 +52,14 @@ func Index(c *RequestContext) ResponseData { var newsItems []templates.TimelineItem 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 { c.Logger.Warn().Err(err).Msg("failed to fetch following feed") } diff --git a/src/website/timeline_helper.go b/src/website/timeline_helper.go index 22c1fb61..03bbc7d6 100644 --- a/src/website/timeline_helper.go +++ b/src/website/timeline_helper.go @@ -20,7 +20,12 @@ import ( "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.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{ OwnerIDs: userIDs, ProjectIDs: projectIDs, + Offset: q.Offset, + Limit: q.Limit, }) } perf.EndBlock()