From dd5ce8074bbdf085f8edb82b2286520f570c61e6 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 1 Mar 2025 18:25:01 +0800 Subject: [PATCH] :bug: Fix wrongly count aggressive view counts --- pkg/internal/services/post_views.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/internal/services/post_views.go b/pkg/internal/services/post_views.go index 55349e5..745fc35 100644 --- a/pkg/internal/services/post_views.go +++ b/pkg/internal/services/post_views.go @@ -35,22 +35,22 @@ func FlushPostViews() { workingQueue := make([]models.PostView, len(postViewQueue)) copy(workingQueue, postViewQueue) clear(postViewQueue) - updateRequiredPost := make(map[uint]bool) + updateRequiredPost := make(map[uint]int) for _, item := range workingQueue { - updateRequiredPost[item.PostID] = true + updateRequiredPost[item.PostID]++ } workingQueue = lo.UniqBy(workingQueue, func(item models.PostView) string { return fmt.Sprintf("%d:%d", item.PostID, item.AccountID) }) _ = database.C.Clauses(clause.OnConflict{DoNothing: true}).CreateInBatches(workingQueue, 1000).Error - for k := range updateRequiredPost { + for k, v := range updateRequiredPost { var count int64 if err := database.C.Model(&models.PostView{}).Where("post_id = ?", k).Count(&count).Error; err != nil { continue } database.C.Model(&models.Post{}).Where("id = ?", k).Updates(map[string]any{ "total_views": count, - "total_aggressive_views": gorm.Expr("total_aggressive_views + ?", count), + "total_aggressive_views": gorm.Expr("total_aggressive_views + ?", v), }) } }