Skip to content

Commit

Permalink
Merge pull request #7 from Parker-Kasiewicz/hydrator_updates
Browse files Browse the repository at this point in the history
caching user metadata error on post lookup
  • Loading branch information
lxcode authored Oct 24, 2024
2 parents dcc2597 + c98e0fd commit 9ddf16a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkg/hydrator/hydrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ func (h *Hydrator) lookupPost(atUrl string) (post *bsky.FeedDefs_PostView, err e
cachedValue, found := h.Cache.Get(key)

if found && cachedValue != nil {
if cachedError, isErr := cachedValue.(error); isErr {
log.Warnf("Cached error for %s: %v", atUrl, cachedError)
return nil, cachedError
}
post = cachedValue.(*bsky.FeedDefs_PostView)
return
}
Expand All @@ -163,12 +167,13 @@ func (h *Hydrator) lookupPost(atUrl string) (post *bsky.FeedDefs_PostView, err e

h.Ratelimit.Take()
output, err := bsky.FeedGetPosts(h.Context, h.Client, []string{atUrl})
if err != nil {
return
}

if len(output.Posts) == 0 {
err = fmt.Errorf("no posts found for %s", atUrl)
}

if err != nil { // caching miss so we don't keep checking
h.Cache.SetWithTTL(key, err, 0, time.Duration(1)*time.Hour*24)
return
}

Expand Down

0 comments on commit 9ddf16a

Please sign in to comment.