MCPcopy Create free account
hub / github.com/GoSimplicity/LinkMe / GetFollowerCount

Method GetFollowerCount

internal/repository/relation.go:115–134  ·  view source on GitHub ↗
(ctx context.Context, userID int64)

Source from the content-addressed store, hash-verified

113}
114
115func (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
136func (r *relationRepository) toDomainRelation(relation dao.Relation) domain.Relation {
137 return domain.Relation{

Callers

nothing calls this directly

Calls 4

GenerateCountCacheKeyMethod · 0.65
GetCountCacheMethod · 0.65
FollowCountMethod · 0.65
SetCountCacheMethod · 0.65

Tested by

no test coverage detected