(ctx context.Context, userID int64)
| 113 | } |
| 114 | |
| 115 | func (r *relationRepository) GetFollowerCount(ctx context.Context, userID int64) (int64, error) { |
| 116 | cacheKey := r.cache.GenerateCountCacheKey(userID, "followers") |
| 117 | if cachedCount, err := r.cache.GetCountCache(ctx, cacheKey); err == nil { |
| 118 | r.logger.Info("Cache hit for follower count", zap.String("key", cacheKey)) |
| 119 | return cachedCount, nil |
| 120 | } |
| 121 | |
| 122 | count, err := r.dao.FollowCount(ctx, userID) |
| 123 | if err != nil { |
| 124 | return 0, err |
| 125 | } |
| 126 | |
| 127 | // 缓存粉丝数 |
| 128 | err = r.cache.SetCountCache(ctx, cacheKey, count.FollowerCount, 5*time.Minute) |
| 129 | if err != nil { |
| 130 | return 0, err |
| 131 | } |
| 132 | |
| 133 | return count.FollowerCount, nil |
| 134 | } |
| 135 | |
| 136 | func (r *relationRepository) toDomainRelation(relation dao.Relation) domain.Relation { |
| 137 | return domain.Relation{ |
nothing calls this directly
no test coverage detected