fixed update user metric incorrect when no user record

pull/400/head
Michael Li 1 year ago
parent ee01658d8a
commit 13acb5256b
No known key found for this signature in database

@ -4,6 +4,10 @@ All notable changes to paopao-ce are documented in this file.
## 0.6.0+dev ([`dev`](https://github.com/rocboss/paopao-ce/tree/dev))
TODO;
## 0.5.1
### Fixed
- fixed update user metric incorrect when no user record.
## 0.5.0
### Added
- add `LoggerOpenObserve` feature use OpenObserve to collect log.[#370](https://github.com/rocboss/paopao-ce/pull/370)

@ -26,13 +26,11 @@ type userMetricSrvA struct {
}
func (s *tweetMetricSrvA) UpdateTweetMetric(metric *cs.TweetMetric) error {
return s.db.Transaction(func(tx *gorm.DB) (err error) {
return s.db.Transaction(func(tx *gorm.DB) error {
postMetric := &dbr.PostMetric{PostId: metric.PostId}
db := s.db.Model(postMetric).Where("post_id=?", metric.PostId)
db.First(postMetric)
tx.Model(postMetric).Where("post_id=?", metric.PostId).First(postMetric)
postMetric.RankScore = metric.RankScore(postMetric.MotivationFactor)
err = db.Save(postMetric).Error
return
return tx.Save(postMetric).Error
})
}
@ -46,13 +44,11 @@ func (s *tweetMetricSrvA) DeleteTweetMetric(postId int64) (err error) {
}
func (s *commentMetricSrvA) UpdateCommentMetric(metric *cs.CommentMetric) error {
return s.db.Transaction(func(tx *gorm.DB) (err error) {
return s.db.Transaction(func(tx *gorm.DB) error {
commentMetric := &dbr.CommentMetric{CommentId: metric.CommentId}
db := s.db.Model(commentMetric).Where("comment_id=?", metric.CommentId)
db.First(commentMetric)
tx.Model(commentMetric).Where("comment_id=?", metric.CommentId).First(commentMetric)
commentMetric.RankScore = metric.RankScore(commentMetric.MotivationFactor)
err = db.Save(commentMetric).Error
return
return tx.Save(commentMetric).Error
})
}
@ -65,14 +61,9 @@ func (s *commentMetricSrvA) DeleteCommentMetric(commentId int64) (err error) {
return (&dbr.CommentMetric{CommentId: commentId}).Delete(s.db)
}
func (s *userMetricSrvA) UpdateUserMetric(userId int64, action uint8) (err error) {
metric := &dbr.UserMetric{}
db := s.db.Model(metric)
if err = db.Where("user_id=?", userId).First(metric).Error; err != nil {
metric = &dbr.UserMetric{
UserId: userId,
}
}
func (s *userMetricSrvA) UpdateUserMetric(userId int64, action uint8) error {
metric := &dbr.UserMetric{UserId: userId}
s.db.Model(metric).Where("user_id=?", userId).First(metric)
metric.LatestTrendsOn = time.Now().Unix()
switch action {
case cs.MetricActionCreateTweet:
@ -82,7 +73,7 @@ func (s *userMetricSrvA) UpdateUserMetric(userId int64, action uint8) (err error
metric.TweetsCount--
}
}
return db.Save(metric).Error
return s.db.Save(metric).Error
}
func (s *userMetricSrvA) AddUserMetric(userId int64) (err error) {

Loading…
Cancel
Save