From 50158d865076de9ac508ad31a5ad2a23daf3c178 Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Tue, 20 Jan 2026 07:44:24 +0000 Subject: [PATCH] appview/db: move timeline-commits logic into MakeTimeline also fixes a subtle bug: when timeline commits are populated from the punchcard, only the current year's commits are available, however the timeline can span across two years (as it does today: Jan 2026, Dec 2025, Nov 2025 ...). Signed-off-by: oppiliappan --- appview/db/profile.go | 23 +++++++++++++++++++++++ appview/state/profile.go | 11 ----------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/appview/db/profile.go b/appview/db/profile.go index 745b7969..37537e27 100644 --- a/appview/db/profile.go +++ b/appview/db/profile.go @@ -98,6 +98,29 @@ func MakeProfileTimeline(e Execer, forDid string) (*models.ProfileTimeline, erro }) } + punchcard, err := MakePunchcard( + e, + orm.FilterEq("did", forDid), + orm.FilterGte("date", time.Now().AddDate(0, -TimeframeMonths, 0)), + ) + if err != nil { + return nil, fmt.Errorf("error getting commits by did: %w", err) + } + for _, punch := range punchcard.Punches { + if punch.Date.After(now) { + continue + } + + monthsAgo := monthsBetween(punch.Date, now) + if monthsAgo >= TimeframeMonths { + // shouldn't happen; but times are weird + continue + } + + idx := monthsAgo + timeline.ByMonth[idx].Commits += punch.Count + } + return &timeline, nil } diff --git a/appview/state/profile.go b/appview/state/profile.go index 1f678a54..c60af271 100644 --- a/appview/state/profile.go +++ b/appview/state/profile.go @@ -162,17 +162,6 @@ func (s *State) profileOverview(w http.ResponseWriter, r *http.Request) { l.Error("failed to create timeline", "err", err) } - // populate commit counts in the timeline, using the punchcard - now := time.Now() - for _, p := range profile.Punchcard.Punches { - years := now.Year() - p.Date.Year() - months := int(now.Month() - p.Date.Month()) - monthsAgo := years*12 + months - if monthsAgo >= 0 && monthsAgo < len(timeline.ByMonth) { - timeline.ByMonth[monthsAgo].Commits += p.Count - } - } - s.pages.ProfileOverview(w, pages.ProfileOverviewParams{ LoggedInUser: s.oauth.GetMultiAccountUser(r), Card: profile, -- 2.51.2