From f6fe5b552d0c13adefc426da7b27859ed59e8dff Mon Sep 17 00:00:00 2001 From: xvhuan Date: Wed, 4 Mar 2026 14:07:17 +0800 Subject: [PATCH] fix(admin): resolve CI lint and user subscriptions regression --- .../handler/admin/account_today_stats_cache.go | 6 +++--- backend/internal/handler/admin/user_handler.go | 13 ++++++++----- backend/internal/repository/user_repo.go | 3 ++- backend/internal/service/user_service.go | 3 ++- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/backend/internal/handler/admin/account_today_stats_cache.go b/backend/internal/handler/admin/account_today_stats_cache.go index 80014903..15cdccef 100644 --- a/backend/internal/handler/admin/account_today_stats_cache.go +++ b/backend/internal/handler/admin/account_today_stats_cache.go @@ -35,12 +35,12 @@ func buildAccountTodayStatsBatchCacheKey(accountIDs []int64) string { } var b strings.Builder b.Grow(len(accountIDs) * 6) - b.WriteString("accounts_today_stats:") + _, _ = b.WriteString("accounts_today_stats:") for i, id := range accountIDs { if i > 0 { - b.WriteByte(',') + _ = b.WriteByte(',') } - b.WriteString(strconv.FormatInt(id, 10)) + _, _ = b.WriteString(strconv.FormatInt(id, 10)) } return b.String() } diff --git a/backend/internal/handler/admin/user_handler.go b/backend/internal/handler/admin/user_handler.go index 05a48b82..5a55ab14 100644 --- a/backend/internal/handler/admin/user_handler.go +++ b/backend/internal/handler/admin/user_handler.go @@ -86,11 +86,14 @@ func (h *UserHandler) List(c *gin.Context) { } filters := service.UserListFilters{ - Status: c.Query("status"), - Role: c.Query("role"), - Search: search, - Attributes: parseAttributeFilters(c), - IncludeSubscriptions: parseBoolQueryWithDefault(c.Query("include_subscriptions"), true), + Status: c.Query("status"), + Role: c.Query("role"), + Search: search, + Attributes: parseAttributeFilters(c), + } + if raw, ok := c.GetQuery("include_subscriptions"); ok { + includeSubscriptions := parseBoolQueryWithDefault(raw, true) + filters.IncludeSubscriptions = &includeSubscriptions } users, total, err := h.adminService.ListUsers(c.Request.Context(), page, pageSize, filters) diff --git a/backend/internal/repository/user_repo.go b/backend/internal/repository/user_repo.go index baf531f3..b56aaaf9 100644 --- a/backend/internal/repository/user_repo.go +++ b/backend/internal/repository/user_repo.go @@ -243,7 +243,8 @@ func (r *userRepository) ListWithFilters(ctx context.Context, params pagination. userMap[u.ID] = &outUsers[len(outUsers)-1] } - if filters.IncludeSubscriptions { + shouldLoadSubscriptions := filters.IncludeSubscriptions == nil || *filters.IncludeSubscriptions + if shouldLoadSubscriptions { // Batch load active subscriptions with groups to avoid N+1. subs, err := r.client.UserSubscription.Query(). Where( diff --git a/backend/internal/service/user_service.go b/backend/internal/service/user_service.go index a6c57048..49ba3645 100644 --- a/backend/internal/service/user_service.go +++ b/backend/internal/service/user_service.go @@ -24,7 +24,8 @@ type UserListFilters struct { Attributes map[int64]string // Custom attribute filters: attributeID -> value // IncludeSubscriptions controls whether ListWithFilters should load active subscriptions. // For large datasets this can be expensive; admin list pages should enable it on demand. - IncludeSubscriptions bool + // nil means not specified (default: load subscriptions for backward compatibility). + IncludeSubscriptions *bool } type UserRepository interface {