|
|
@ -41,6 +41,10 @@ const (
|
|
|
|
const (
|
|
|
|
const (
|
|
|
|
_trendsActionCreateTweet uint8 = iota
|
|
|
|
_trendsActionCreateTweet uint8 = iota
|
|
|
|
_trendsActionDeleteTweet
|
|
|
|
_trendsActionDeleteTweet
|
|
|
|
|
|
|
|
_trendsActionFollowUser
|
|
|
|
|
|
|
|
_trendsActionUnfollowUser
|
|
|
|
|
|
|
|
_trendsActionAddFriend
|
|
|
|
|
|
|
|
_trendsActionDeleteFriend
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type cacheUnreadMsgEvent struct {
|
|
|
|
type cacheUnreadMsgEvent struct {
|
|
|
@ -78,15 +82,15 @@ type trendsActionEvent struct {
|
|
|
|
ac core.AppCache
|
|
|
|
ac core.AppCache
|
|
|
|
ds core.DataService
|
|
|
|
ds core.DataService
|
|
|
|
action uint8
|
|
|
|
action uint8
|
|
|
|
userId int64
|
|
|
|
userIds []int64
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func onTrendsActionEvent(action uint8, userId int64) {
|
|
|
|
func onTrendsActionEvent(action uint8, userIds ...int64) {
|
|
|
|
events.OnEvent(&trendsActionEvent{
|
|
|
|
events.OnEvent(&trendsActionEvent{
|
|
|
|
ac: _ac,
|
|
|
|
ac: _ac,
|
|
|
|
ds: _ds,
|
|
|
|
ds: _ds,
|
|
|
|
action: action,
|
|
|
|
action: action,
|
|
|
|
userId: userId,
|
|
|
|
userIds: userIds,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -246,23 +250,39 @@ func (e *trendsActionEvent) Action() (err error) {
|
|
|
|
switch e.action {
|
|
|
|
switch e.action {
|
|
|
|
case _trendsActionCreateTweet:
|
|
|
|
case _trendsActionCreateTweet:
|
|
|
|
logrus.Debug("trigger trendsActionEvent by create tweet ")
|
|
|
|
logrus.Debug("trigger trendsActionEvent by create tweet ")
|
|
|
|
e.ds.UpdateUserMetric(e.userId, cs.MetricActionCreateTweet)
|
|
|
|
e.updateUserMetric(cs.MetricActionCreateTweet)
|
|
|
|
goto ExpireTrends
|
|
|
|
e.expireFriendTrends()
|
|
|
|
case _trendsActionDeleteTweet:
|
|
|
|
case _trendsActionDeleteTweet:
|
|
|
|
logrus.Debug("trigger trendsActionEvent by delete tweet ")
|
|
|
|
logrus.Debug("trigger trendsActionEvent by delete tweet ")
|
|
|
|
e.ds.UpdateUserMetric(e.userId, cs.MetricActionDeleteTweet)
|
|
|
|
e.updateUserMetric(cs.MetricActionDeleteTweet)
|
|
|
|
goto ExpireTrends
|
|
|
|
e.expireFriendTrends()
|
|
|
|
|
|
|
|
case _trendsActionAddFriend, _trendsActionDeleteFriend,
|
|
|
|
|
|
|
|
_trendsActionFollowUser, _trendsActionUnfollowUser:
|
|
|
|
|
|
|
|
e.expireMyTrends()
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
// nothing
|
|
|
|
// nothing
|
|
|
|
goto JustReturn
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ExpireTrends:
|
|
|
|
return
|
|
|
|
if friendIds, err := e.ds.MyFriendIds(e.userId); err == nil {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (e *trendsActionEvent) updateUserMetric(action uint8) {
|
|
|
|
|
|
|
|
for _, userId := range e.userIds {
|
|
|
|
|
|
|
|
e.ds.UpdateUserMetric(userId, action)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (e *trendsActionEvent) expireFriendTrends() {
|
|
|
|
|
|
|
|
for _, userId := range e.userIds {
|
|
|
|
|
|
|
|
if friendIds, err := e.ds.MyFriendIds(userId); err == nil {
|
|
|
|
for _, id := range friendIds {
|
|
|
|
for _, id := range friendIds {
|
|
|
|
e.ac.DelAny(fmt.Sprintf("%s%d:*", conf.PrefixIdxTrends, id))
|
|
|
|
e.ac.DelAny(fmt.Sprintf("%s%d:*", conf.PrefixIdxTrends, id))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
JustReturn:
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (e *trendsActionEvent) expireMyTrends() {
|
|
|
|
|
|
|
|
for _, userId := range e.userIds {
|
|
|
|
|
|
|
|
e.ac.DelAny(fmt.Sprintf("%s%d:*", conf.PrefixIdxTrends, userId))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|