Merge branch 'beta' into x/gorm

pull/398/head
Michael Li 1 year ago
commit 0ef6297ba9
No known key found for this signature in database

@ -68,7 +68,7 @@ func initCacheKeyPool() {
KeyUnreadMsg = intKeyPool[int64](poolSize, PrefixUnreadmsg) KeyUnreadMsg = intKeyPool[int64](poolSize, PrefixUnreadmsg)
KeyOnlineUser = intKeyPool[int64](poolSize, PrefixOnlineUser) KeyOnlineUser = intKeyPool[int64](poolSize, PrefixOnlineUser)
KeyUserInfoById = intKeyPool[int64](poolSize, PrefixUserInfoById) KeyUserInfoById = intKeyPool[int64](poolSize, PrefixUserInfoById)
KeyUserInfoByName = strKeyPool(poolSize, PrefixUserInfoById) KeyUserInfoByName = strKeyPool(poolSize, PrefixUserInfoByName)
KeyUserProfileByName = strKeyPool(poolSize, prefixUserProfileByName) KeyUserProfileByName = strKeyPool(poolSize, prefixUserProfileByName)
KeyMyFriendIds = intKeyPool[int64](poolSize, PrefixMyFriendIds) KeyMyFriendIds = intKeyPool[int64](poolSize, PrefixMyFriendIds)
KeyMyFollowIds = intKeyPool[int64](poolSize, PrefixMyFollowIds) KeyMyFollowIds = intKeyPool[int64](poolSize, PrefixMyFollowIds)

@ -18,6 +18,11 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
type BaseCacheEvent struct {
event.UnimplementedEvent
ac core.AppCache
}
type expireIndexTweetsEvent struct { type expireIndexTweetsEvent struct {
event.UnimplementedEvent event.UnimplementedEvent
ac core.AppCache ac core.AppCache
@ -70,6 +75,12 @@ type cacheMyFollowIdsEvent struct {
expire int64 expire int64
} }
func NewBaseCacheEvent(ac core.AppCache) *BaseCacheEvent {
return &BaseCacheEvent{
ac: ac,
}
}
func OnExpireIndexTweetEvent(userId int64) { func OnExpireIndexTweetEvent(userId int64) {
// TODO: 这里暴躁的将所有 最新/热门/关注 的推文列表缓存都过期掉,后续需要更精细话处理 // TODO: 这里暴躁的将所有 最新/热门/关注 的推文列表缓存都过期掉,后续需要更精细话处理
events.OnEvent(&expireIndexTweetsEvent{ events.OnEvent(&expireIndexTweetsEvent{
@ -144,6 +155,35 @@ func OnCacheMyFollowIdsEvent(urs core.UserRelationService, userId int64, key ...
}) })
} }
func (e *BaseCacheEvent) ExpireUserInfo(id int64, name string) error {
keys := make([]string, 0, 2)
if id >= 0 {
keys = append(keys, conf.KeyUserInfoById.Get(id))
}
if len(name) > 0 {
keys = append(keys, conf.KeyUserInfoByName.Get(name))
}
return e.ac.Delete(keys...)
}
func (e *BaseCacheEvent) ExpireUserProfile(name string) error {
if len(name) > 0 {
return e.ac.Delete(conf.KeyUserProfileByName.Get(name))
}
return nil
}
func (e *BaseCacheEvent) ExpireUserData(id int64, name string) error {
keys := make([]string, 0, 3)
if id >= 0 {
keys = append(keys, conf.KeyUserInfoById.Get(id))
}
if len(name) > 0 {
keys = append(keys, conf.KeyUserInfoByName.Get(name), conf.KeyUserProfileByName.Get(name))
}
return e.ac.Delete(keys...)
}
func (e *expireIndexTweetsEvent) Name() string { func (e *expireIndexTweetsEvent) Name() string {
return "expireIndexTweetsEvent" return "expireIndexTweetsEvent"
} }

@ -353,6 +353,8 @@ func (s *coreSrv) ChangeNickname(req *web.ChangeNicknameReq) mir.Error {
logrus.Errorf("Ds.UpdateUser err: %s", err) logrus.Errorf("Ds.UpdateUser err: %s", err)
return xerror.ServerError return xerror.ServerError
} }
// 缓存处理
onChangeUsernameEvent(user.ID, user.Username)
return nil return nil
} }
@ -377,6 +379,8 @@ func (s *coreSrv) ChangeAvatar(req *web.ChangeAvatarReq) (xerr mir.Error) {
logrus.Errorf("Ds.UpdateUser failed: %s", err) logrus.Errorf("Ds.UpdateUser failed: %s", err)
return xerror.ServerError return xerror.ServerError
} }
// 缓存处理
onChangeUsernameEvent(user.ID, user.Username)
return nil return nil
} }

@ -13,6 +13,7 @@ import (
"github.com/rocboss/paopao-ce/internal/core" "github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/internal/core/cs" "github.com/rocboss/paopao-ce/internal/core/cs"
"github.com/rocboss/paopao-ce/internal/core/ms" "github.com/rocboss/paopao-ce/internal/core/ms"
"github.com/rocboss/paopao-ce/internal/dao/cache"
"github.com/rocboss/paopao-ce/internal/events" "github.com/rocboss/paopao-ce/internal/events"
"github.com/rocboss/paopao-ce/internal/model/joint" "github.com/rocboss/paopao-ce/internal/model/joint"
"github.com/rocboss/paopao-ce/internal/model/web" "github.com/rocboss/paopao-ce/internal/model/web"
@ -98,6 +99,20 @@ type trendsActionEvent struct {
userIds []int64 userIds []int64
} }
type changeUserEvent struct {
*cache.BaseCacheEvent
userId int64
username string
}
func onChangeUsernameEvent(id int64, name string) {
events.OnEvent(&changeUserEvent{
BaseCacheEvent: cache.NewBaseCacheEvent(_ac),
userId: id,
username: name,
})
}
func onTrendsActionEvent(action uint8, userIds ...int64) { func onTrendsActionEvent(action uint8, userIds ...int64) {
events.OnEvent(&trendsActionEvent{ events.OnEvent(&trendsActionEvent{
ac: _ac, ac: _ac,
@ -322,3 +337,11 @@ func (e *tweetActionEvent) Action() (err error) {
} }
return return
} }
func (e *changeUserEvent) Name() string {
return "changeUserEvent"
}
func (e *changeUserEvent) Action() error {
return e.ExpireUserData(e.userId, e.username)
}

Loading…
Cancel
Save