Skip to content

Commit

Permalink
feat: cache增加获取所有好友
Browse files Browse the repository at this point in the history
  • Loading branch information
Redmomn committed Jun 17, 2024
1 parent 9e5471f commit 6b660aa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions client/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ func (c *QQClient) GetCachedFriendInfo(uin uint32) (*entity.Friend, error) {
return c.cache.GetFriend(uin), nil
}

// GetCachedAllFriendsInfo 获取所有好友信息(缓存)
func (c *QQClient) GetCachedAllFriendsInfo() (map[uint32]*entity.Friend, error) {
if c.cache.FriendCacheIsEmpty() {
if err := c.RefreshFriendCache(); err != nil {
return nil, err
}
}
return c.cache.GetAllFriends(), nil
}

// GetCachedGroupInfo 获取群信息(缓存)
func (c *QQClient) GetCachedGroupInfo(groupUin uint32) (*entity.Group, error) {
if c.cache.GroupInfoCacheIsEmpty() {
Expand Down
10 changes: 10 additions & 0 deletions client/internal/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ func (c *Cache) GetFriend(uin uint32) *entity.Friend {
return v
}

// GetAllFriends 获取所有好友信息
func (c *Cache) GetAllFriends() map[uint32]*entity.Friend {
friends := make(map[uint32]*entity.Friend, 64)
rangeCacheOf[entity.Friend](c, func(k uint32, friend *entity.Friend) bool {
friends[k] = friend
return true
})
return friends
}

// GetGroupInfo 获取群信息
func (c *Cache) GetGroupInfo(groupUin uint32) *entity.Group {
v, _ := getCacheOf[entity.Group](c, groupUin)
Expand Down

0 comments on commit 6b660aa

Please sign in to comment.