Skip to content

Commit

Permalink
fix: cache
Browse files Browse the repository at this point in the history
  • Loading branch information
bookpanda committed Jul 7, 2024
1 parent 5e09901 commit d8af1a1
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions internal/group/group.service.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (s *serviceImpl) findByUserId(userId string) (*model.Group, error) {
cacheKey := groupByUserIdKey(userId)
cachedGroup := &model.Group{}

if err := s.cache.GetValue(cacheKey, &cachedGroup); err == nil {
if err := s.cache.GetValue(cacheKey, cachedGroup); err == nil {
s.log.Named("findByUserId").Info("GetValue: Group found in cache", zap.String("userId", userId))
return cachedGroup, nil
}
Expand Down Expand Up @@ -372,9 +372,8 @@ func (s *serviceImpl) Join(_ context.Context, in *proto.JoinGroupRequest) (*prot
}

func (s *serviceImpl) updateGroupCacheByUserId(group *model.Group) error {
groupRPC := ModelToProto(group)
for _, member := range group.Members {
if err := s.cache.SetValue(groupByUserIdKey(member.ID.String()), groupRPC, s.conf.CacheTTL); err != nil {
if err := s.cache.SetValue(groupByUserIdKey(member.ID.String()), group, s.conf.CacheTTL); err != nil {
return fmt.Errorf("failed to update group cache: %w", err)
}
}
Expand Down

0 comments on commit d8af1a1

Please sign in to comment.