From 308ef2687c086e239e39e66d309eb06819cba32f Mon Sep 17 00:00:00 2001 From: Michael Li Date: Sat, 7 Oct 2023 17:57:28 +0800 Subject: [PATCH] optimize get index trends info logic --- internal/dao/jinzhu/metrics.go | 3 +++ internal/dao/jinzhu/trends.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/dao/jinzhu/metrics.go b/internal/dao/jinzhu/metrics.go index 175ad6bc..5df75fe9 100644 --- a/internal/dao/jinzhu/metrics.go +++ b/internal/dao/jinzhu/metrics.go @@ -5,6 +5,8 @@ package jinzhu import ( + "time" + "github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core/cs" "github.com/rocboss/paopao-ce/internal/dao/jinzhu/dbr" @@ -71,6 +73,7 @@ func (s *userMetricSrvA) UpdateUserMetric(userId int64, action uint8) (err error UserId: userId, } } + metric.LatestTrendsOn = time.Now().Unix() switch action { case cs.MetricActionCreateTweet: metric.TweetsCount++ diff --git a/internal/dao/jinzhu/trends.go b/internal/dao/jinzhu/trends.go index e4fa8061..2d4aff4b 100644 --- a/internal/dao/jinzhu/trends.go +++ b/internal/dao/jinzhu/trends.go @@ -27,7 +27,7 @@ func (s *trendsSrvA) GetIndexTrends(userId int64, limit int, offset int) (res [] if offset >= 0 && limit > 0 { db = db.Limit(limit).Offset(offset) } - if err = db.Order("r.style ASC").Select("username", "nickname", "avatar").Find(&res).Error; err == nil { + if err = db.Order("r.style ASC, m.latest_trends_on DESC").Select("username", "nickname", "avatar").Find(&res).Error; err == nil { res = cs.DistinctTrends(res) } return