Monorepo for Tangled

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 <me@oppi.li>

authored by

oppiliappan and committed by tangled.org 50158d86 94470cd6

+23 -11
+23
appview/db/profile.go
··· 98 98 }) 99 99 } 100 100 101 + punchcard, err := MakePunchcard( 102 + e, 103 + orm.FilterEq("did", forDid), 104 + orm.FilterGte("date", time.Now().AddDate(0, -TimeframeMonths, 0)), 105 + ) 106 + if err != nil { 107 + return nil, fmt.Errorf("error getting commits by did: %w", err) 108 + } 109 + for _, punch := range punchcard.Punches { 110 + if punch.Date.After(now) { 111 + continue 112 + } 113 + 114 + monthsAgo := monthsBetween(punch.Date, now) 115 + if monthsAgo >= TimeframeMonths { 116 + // shouldn't happen; but times are weird 117 + continue 118 + } 119 + 120 + idx := monthsAgo 121 + timeline.ByMonth[idx].Commits += punch.Count 122 + } 123 + 101 124 return &timeline, nil 102 125 } 103 126
-11
appview/state/profile.go
··· 162 162 l.Error("failed to create timeline", "err", err) 163 163 } 164 164 165 - // populate commit counts in the timeline, using the punchcard 166 - now := time.Now() 167 - for _, p := range profile.Punchcard.Punches { 168 - years := now.Year() - p.Date.Year() 169 - months := int(now.Month() - p.Date.Month()) 170 - monthsAgo := years*12 + months 171 - if monthsAgo >= 0 && monthsAgo < len(timeline.ByMonth) { 172 - timeline.ByMonth[monthsAgo].Commits += p.Count 173 - } 174 - } 175 - 176 165 s.pages.ProfileOverview(w, pages.ProfileOverviewParams{ 177 166 LoggedInUser: s.oauth.GetMultiAccountUser(r), 178 167 Card: profile,