Skip to content

Commit

Permalink
Increase non-tokened-tweet links cache duration to default tweet cach…
Browse files Browse the repository at this point in the history
…e duration (#528)
  • Loading branch information
pajlada authored Sep 10, 2023
1 parent c2f3c3b commit 53f0bec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Breaking: Remove the `/twitchemotes/` endpoints. See [issue 332](https://github.com/Chatterino/api/issues/332) for more information. (#465)
- Minor: Use Twitter OG tags if no Twitter credentials are configured. (#522)
- Minor: Support `x.com` for tweets. (#527)
- Minor: Increase tweet cache duration for non-credentialed requests to 24h. Currently not configurable. (#528)
- Fix: We do some more YouTube video ID parsing to ensure broken links (such as `youtube.com/watch?v=foobar?feature=share`) still return the actual video ID, since this is how the browser operates. (#488)
- Dev: Document the `log-development` setting. (#491)
- Dev: Document the `log-level` setting. (#490)
Expand Down
7 changes: 6 additions & 1 deletion internal/resolvers/default/link_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package defaultresolver
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -51,9 +52,12 @@ func (l *LinkLoader) Load(ctx context.Context, urlString string, r *http.Request
}

extraHeaders := make(map[string]string)
cacheDur := cache.NoSpecialDur
ctx, isTwitterRequest := twitter.Check(ctx, requestUrl)
if isTwitterRequest {
extraHeaders["User-Agent"] = fmt.Sprintf("chatterino-api-cache/%s link-resolver (bot)", version.Version)
// TODO: Use twitter-tweet-cache-duration?
cacheDur = time.Hour * 24
}

resp, err := resolver.RequestGETWithHeaders(requestUrl.String(), extraHeaders)
Expand Down Expand Up @@ -160,5 +164,6 @@ func (l *LinkLoader) Load(ctx context.Context, urlString string, r *http.Request
response.Thumbnail = utils.FormatThumbnailURL(l.baseURL, r, resp.Request.URL.String())
}

return utils.MarshalNoDur(response)
finalData, finalErr := json.Marshal(response)
return finalData, nil, nil, cacheDur, finalErr
}

0 comments on commit 53f0bec

Please sign in to comment.