chore: add logs on sadhna API

This commit is contained in:
Krispire Admin
2026-06-09 12:10:45 +05:30
parent 0d189739d6
commit 0188a34cf6
2 changed files with 14 additions and 3 deletions
+1 -1
View File
@@ -254,7 +254,7 @@ func (r *PostRepo) PostCountsByDate(ctx context.Context, userID string, since ti
tz = "UTC"
}
rows, err := r.pg.Pool.Query(ctx, `
SELECT (created_at AT TIME ZONE $3)::date AS d, count(*) AS n
SELECT (created_at AT TIME ZONE $3::text)::date AS d, count(*) AS n
FROM posts
WHERE user_id = $1 AND created_at >= $2
GROUP BY d`,
+13 -2
View File
@@ -148,11 +148,18 @@ func (s *SadhnaService) Dashboard(ctx context.Context, userID string) (*model.Sa
logs, err := s.logs.ListSince(ctx, userID, since)
if err != nil {
s.logger.Error("sadhna dashboard: list logs failed",
zap.String("user", userID), zap.Error(err))
return nil, err
}
// The quote half is non-critical: if it fails (e.g. an unrecognized
// timezone in the AT TIME ZONE bucketing), log it and degrade to "no
// quotes" rather than 500-ing the whole dashboard.
postsByDay, err := s.posts.PostCountsByDate(ctx, userID, since, tz)
if err != nil {
return nil, err
s.logger.Error("sadhna dashboard: post counts failed",
zap.String("user", userID), zap.String("tz", tz), zap.Error(err))
postsByDay = map[string]int{}
}
// Index the chanting half by day.
@@ -398,11 +405,15 @@ func (s *SadhnaService) History(ctx context.Context, userID string, from, to tim
tz, _ := s.resolveTZ(ctx, userID)
logs, err := s.logs.ListSince(ctx, userID, from)
if err != nil {
s.logger.Error("sadhna history: list logs failed",
zap.String("user", userID), zap.Error(err))
return nil, err
}
postsByDay, err := s.posts.PostCountsByDate(ctx, userID, from, tz)
if err != nil {
return nil, err
s.logger.Error("sadhna history: post counts failed",
zap.String("user", userID), zap.String("tz", tz), zap.Error(err))
postsByDay = map[string]int{}
}
chantByDay := make(map[string]bool, len(logs))