Skip to content

Commit

Permalink
patching profile lookup error caching
Browse files Browse the repository at this point in the history
  • Loading branch information
Parker-Kasiewicz committed Oct 20, 2024
1 parent 96ef537 commit e5528be
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions pkg/hydrator/hydrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,26 @@ func (h *Hydrator) lookupProfileFromIdentity(identity *atpidentity.Identity) (pr
cachedValue, found := h.Cache.Get(key)

if found && cachedValue != nil {
if cachedError, isErr := cachedValue.(error); isErr {
log.Warnf("Cached error for %s: %v", identity.Handle.String(), cachedError)
return nil, cachedError
}
profile = cachedValue.(*bsky.ActorDefs_ProfileViewDetailed)
return
}

h.Ratelimit.Take()
profile, err = bsky.ActorGetProfile(h.Context, h.Client, identity.Handle.String())

// Set the cache
if err == nil {
h.Cache.SetWithTTL(key, profile, 0, time.Duration(1)*time.Hour*24)
if err != nil { // Cache if error looking up profile like suspended
log.Warnf("Profile lookup failed for identity %s: %s", identity.Handle.String(), err)
h.Cache.SetWithTTL(key, err, 0, time.Duration(1)*time.Hour*24)
return nil, err
}

return
h.Cache.SetWithTTL(key, profile, 0, time.Duration(1)*time.Hour*24)

return profile, nil
}

func (h *Hydrator) lookupProfile(did string) (profile *bsky.ActorDefs_ProfileViewDetailed, err error) {
Expand Down

0 comments on commit e5528be

Please sign in to comment.