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,