summaryrefslogtreecommitdiff
path: root/internal/transport/controller.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2022-10-08 12:50:16 +0100
committerLibravatar GitHub <noreply@github.com>2022-10-08 13:50:16 +0200
commite58a6a2da3b808ca21d1ef1c1ed83ad932dd9dd6 (patch)
tree680483bbde0ee6712563051696278a34f404b035 /internal/transport/controller.go
parent[feature] `oob` oauth token support (#889) (diff)
downloadgotosocial-e58a6a2da3b808ca21d1ef1c1ed83ad932dd9dd6.tar.xz
[performance] cache domains after max retries in transport (#884)
Diffstat (limited to 'internal/transport/controller.go')
-rw-r--r--internal/transport/controller.go26
1 files changed, 17 insertions, 9 deletions
diff --git a/internal/transport/controller.go b/internal/transport/controller.go
index 5a72871d8..4db8ee00e 100644
--- a/internal/transport/controller.go
+++ b/internal/transport/controller.go
@@ -51,7 +51,8 @@ type controller struct {
fedDB federatingdb.DB
clock pub.Clock
client pub.HttpClient
- cache cache.Cache[string, *transport]
+ trspCache cache.Cache[string, *transport]
+ badHosts cache.Cache[string, struct{}]
userAgent string
}
@@ -66,13 +67,20 @@ func NewController(db db.DB, federatingDB federatingdb.DB, clock pub.Clock, clie
fedDB: federatingDB,
clock: clock,
client: client,
- cache: cache.New[string, *transport](),
+ trspCache: cache.New[string, *transport](),
+ badHosts: cache.New[string, struct{}](),
userAgent: fmt.Sprintf("%s; %s (gofed/activity gotosocial-%s)", applicationName, host, version),
}
- // Transport cache has TTL=1hr freq=1m
- c.cache.SetTTL(time.Hour, false)
- if !c.cache.Start(time.Minute) {
+ // Transport cache has TTL=1hr freq=1min
+ c.trspCache.SetTTL(time.Hour, false)
+ if !c.trspCache.Start(time.Minute) {
+ log.Panic("failed to start transport controller cache")
+ }
+
+ // Bad hosts cache has TTL=15min freq=1min
+ c.badHosts.SetTTL(15*time.Minute, false)
+ if !c.badHosts.Start(time.Minute) {
log.Panic("failed to start transport controller cache")
}
@@ -89,7 +97,7 @@ func (c *controller) NewTransport(pubKeyID string, privkey *rsa.PrivateKey) (Tra
pubStr := privkeyToPublicStr(privkey)
// First check for cached transport
- transp, ok := c.cache.Get(pubStr)
+ transp, ok := c.trspCache.Get(pubStr)
if ok {
return transp, nil
}
@@ -102,13 +110,13 @@ func (c *controller) NewTransport(pubKeyID string, privkey *rsa.PrivateKey) (Tra
}
// Cache this transport under pubkey
- if !c.cache.Put(pubStr, transp) {
+ if !c.trspCache.Put(pubStr, transp) {
var cached *transport
- cached, ok = c.cache.Get(pubStr)
+ cached, ok = c.trspCache.Get(pubStr)
if !ok {
// Some ridiculous race cond.
- c.cache.Set(pubStr, transp)
+ c.trspCache.Set(pubStr, transp)
} else {
// Use already cached
transp = cached