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