diff options
author | 2022-03-15 15:01:19 +0100 | |
---|---|---|
committer | 2022-03-15 15:01:19 +0100 | |
commit | e63b6531994adcf976d8e15c2b791682b8531e7d (patch) | |
tree | 6be094842816c978a3dda349c21ccc49ae8b4b95 /internal/transport/dereference.go | |
parent | [bugfix] Fix bug where admin panel could not be accessed at `/admin` (#427) (diff) | |
download | gotosocial-e63b6531994adcf976d8e15c2b791682b8531e7d.tar.xz |
[performance] Add dereference shortcuts to avoid making http calls to self (#430)
* update transport (controller) to allow shortcuts
* go fmt
* expose underlying sig transport to allow test sigs
Diffstat (limited to 'internal/transport/dereference.go')
-rw-r--r-- | internal/transport/dereference.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/internal/transport/dereference.go b/internal/transport/dereference.go index 5ef6db9a7..61d99c5c5 100644 --- a/internal/transport/dereference.go +++ b/internal/transport/dereference.go @@ -23,10 +23,29 @@ import ( "net/url" "github.com/sirupsen/logrus" + "github.com/spf13/viper" + "github.com/superseriousbusiness/gotosocial/internal/config" + "github.com/superseriousbusiness/gotosocial/internal/uris" ) func (t *transport) Dereference(ctx context.Context, iri *url.URL) ([]byte, error) { l := logrus.WithField("func", "Dereference") + + // if the request is to us, we can shortcut for certain URIs rather than going through + // the normal request flow, thereby saving time and energy + if iri.Host == viper.GetString(config.Keys.Host) { + if uris.IsFollowersPath(iri) { + // the request is for followers of one of our accounts, which we can shortcut + return t.dereferenceFollowersShortcut(ctx, iri) + } + + if uris.IsUserPath(iri) { + // the request is for one of our accounts, which we can shortcut + return t.dereferenceUserShortcut(ctx, iri) + } + } + + // the request is either for a remote host or for us but we don't have a shortcut, so continue as normal l.Debugf("performing GET to %s", iri.String()) return t.sigTransport.Dereference(ctx, iri) } |