refactor: restore stored aggregates with incremental update on edit

- Restore TotalWorkSeconds, CurrentStreak, LongestStreak writes in
  computeAndAwardXP and updateStreak (incremental on clock out)
- Add recalcDayWorkSeconds and recalcAggregates for event edit path
  (recompute day + total + streak from scratch when events change)
- Call recalcAggregates after editEventTimeSet, deleteEventConfirm,
  addEventDo in calendar.go
- Remove runtime computeStreaks and totalWorkSeconds (N+1 scan)
  from RPG display, burnout, and clockOut
- Add SetDailyWorkSeconds, SumDailyWorkSeconds store methods
- Clean up unused dead functions and dead code in rpg.go
This commit is contained in:
2026-06-25 02:19:40 +03:30
parent 4fcb694418
commit 5cd811e057
4 changed files with 147 additions and 60 deletions

View File

@@ -510,7 +510,7 @@ func (h *Handler) editEventTimeSet(ctx context.Context, chatID int64, msgID int,
}
t := time.Unix(event.OccurredAt, 0).In(loc)
newTime := time.Date(t.Year(), t.Month(), t.Day(), hh, mm, 0, 0, loc)
date := t.Format(DateLayout)
date := newTime.Format(DateLayout)
// Reject if the new time collides with another event's timestamp
events, err := h.DB.EventsForDayByDate(user.ID, date)
@@ -563,6 +563,8 @@ func (h *Handler) editEventTimeSet(ctx context.Context, chatID int64, msgID int,
h.sendDayView(ctx, chatID, msgID, user, date, loc, false)
return
}
h.recalcDayWorkSeconds(user.ID, date, loc)
h.recalcAggregates(user.ID, loc)
h.sendDayView(ctx, chatID, msgID, user, date, loc, false)
}
@@ -635,6 +637,8 @@ func (h *Handler) deleteEventConfirm(ctx context.Context, chatID int64, msgID in
}
}
h.recalcDayWorkSeconds(user.ID, date, loc)
h.recalcAggregates(user.ID, loc)
h.sendDayView(ctx, chatID, msgID, user, date, loc, false)
}
@@ -707,6 +711,8 @@ func (h *Handler) addEventDo(ctx context.Context, chatID int64, msgID int, user
return
}
h.recalcDayWorkSeconds(user.ID, date, loc)
h.recalcAggregates(user.ID, loc)
h.sendDayView(ctx, chatID, msgID, user, date, loc, false)
}