From 829414391bc51ef12cc98c592d79e5ccfaaafa65 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Fri, 11 Oct 2024 01:10:44 +0800 Subject: [PATCH] fix lint --- Taskfile.yaml | 2 +- internal/collections/infra/mysql_repo.go | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Taskfile.yaml b/Taskfile.yaml index ff17b7a14..4b0ddcc49 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -35,7 +35,7 @@ tasks: silent: true desc: Run 'golangci-lint' cmds: - - golangci-lint run --fix + - golangci-lint --path-prefix "{{ .USER_WORKING_DIR }}" run --fix test: desc: Run mocked tests, need nothing. diff --git a/internal/collections/infra/mysql_repo.go b/internal/collections/infra/mysql_repo.go index bbe3d3411..963a089bf 100644 --- a/internal/collections/infra/mysql_repo.go +++ b/internal/collections/infra/mysql_repo.go @@ -198,7 +198,9 @@ func (r mysqlRepo) updateOrCreateSubjectCollection( r.updateSubject(ctx, subject.ID) if obj.Rate != originalCollection.Rate { - r.reCountSubjectRate(ctx, subject.ID, originalCollection.Rate, obj.Rate) + if err := r.reCountSubjectRate(ctx, subject.ID, originalCollection.Rate, obj.Rate); err != nil { + r.log.Error("failed to update collection counts", zap.Error(err), zap.Uint32("subject_id", subject.ID)) + } } return nil @@ -594,6 +596,7 @@ func (r mysqlRepo) reCountSubjectCollection(ctx context.Context, subjectID model }) } +//nolint:mnd func (r mysqlRepo) reCountSubjectRate(ctx context.Context, subjectID model.SubjectID, before uint8, after uint8) error { var counts []struct { Rate uint8 `gorm:"rate"` @@ -603,7 +606,9 @@ func (r mysqlRepo) reCountSubjectRate(ctx context.Context, subjectID model.Subje return r.q.Transaction(func(tx *query.Query) error { err := tx.DB().WithContext(ctx).Raw(` select interest_rate as rate, count(interest_rate) as total from chii_subject_interests - where interest_subject_id = ? and interest_private = 0 and interest_rate != 0 and ((interest_rate = ?) or (interest_rate = ?)) + where interest_subject_id = ? and + interest_private = 0 and + interest_rate != 0 and ((interest_rate = ?) or (interest_rate = ?)) group by interest_rate `, subjectID, before, after).Scan(&counts).Error if err != nil {