summaryrefslogtreecommitdiff
path: root/internal/federation/federatingdb
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2025-04-06 14:39:40 +0200
committerLibravatar GitHub <noreply@github.com>2025-04-06 14:39:40 +0200
commit8ae2440da3a9b66c379c5a9444b50e758deef61b (patch)
tree06b3ba58208434f6ddbd198a396159ac2c4d9c80 /internal/federation/federatingdb
parent[feature] Allow deleting avatar + header via settings panel (#3970) (diff)
downloadgotosocial-8ae2440da3a9b66c379c5a9444b50e758deef61b.tar.xz
[chore] Migrate accounts to new table, relax uniqueness constraint of actor `url` and collections (#3928)
* [chore] Migrate accounts to new table, relax uniqueness constraint of actor url and collections * fiddle with it! (that's what she said) * remove unused cache fields * sillyness * fix tiny whoopsie
Diffstat (limited to 'internal/federation/federatingdb')
-rw-r--r--internal/federation/federatingdb/followers.go2
-rw-r--r--internal/federation/federatingdb/following.go2
-rw-r--r--internal/federation/federatingdb/outbox.go4
-rw-r--r--internal/federation/federatingdb/util.go64
4 files changed, 9 insertions, 63 deletions
diff --git a/internal/federation/federatingdb/followers.go b/internal/federation/federatingdb/followers.go
index eb46ce83f..eb224960e 100644
--- a/internal/federation/federatingdb/followers.go
+++ b/internal/federation/federatingdb/followers.go
@@ -33,7 +33,7 @@ import (
//
// The library makes this call only after acquiring a lock first.
func (f *federatingDB) Followers(ctx context.Context, actorIRI *url.URL) (followers vocab.ActivityStreamsCollection, err error) {
- acct, err := f.getAccountForIRI(ctx, actorIRI)
+ acct, err := f.state.DB.GetAccountByURI(ctx, actorIRI.String())
if err != nil {
return nil, err
}
diff --git a/internal/federation/federatingdb/following.go b/internal/federation/federatingdb/following.go
index fc7b45268..793bdc9d5 100644
--- a/internal/federation/federatingdb/following.go
+++ b/internal/federation/federatingdb/following.go
@@ -32,7 +32,7 @@ import (
//
// The library makes this call only after acquiring a lock first.
func (f *federatingDB) Following(ctx context.Context, actorIRI *url.URL) (following vocab.ActivityStreamsCollection, err error) {
- acct, err := f.getAccountForIRI(ctx, actorIRI)
+ acct, err := f.state.DB.GetAccountByURI(ctx, actorIRI.String())
if err != nil {
return nil, err
}
diff --git a/internal/federation/federatingdb/outbox.go b/internal/federation/federatingdb/outbox.go
index 7bcc1f37a..116dde56f 100644
--- a/internal/federation/federatingdb/outbox.go
+++ b/internal/federation/federatingdb/outbox.go
@@ -46,12 +46,12 @@ func (f *federatingDB) SetOutbox(ctx context.Context, outbox vocab.ActivityStrea
return nil
}
-// OutboxForInbox fetches the corresponding actor's outbox IRI for the
+// OutboxForInbox fetches the corresponding local actor's outbox IRI for the
// actor's inbox IRI.
//
// The library makes this call only after acquiring a lock first.
func (f *federatingDB) OutboxForInbox(ctx context.Context, inboxIRI *url.URL) (outboxIRI *url.URL, err error) {
- acct, err := f.getAccountForIRI(ctx, inboxIRI)
+ acct, err := f.state.DB.GetOneAccountByInboxURI(ctx, inboxIRI.String())
if err != nil {
return nil, err
}
diff --git a/internal/federation/federatingdb/util.go b/internal/federation/federatingdb/util.go
index 47390c0f6..6d5334076 100644
--- a/internal/federation/federatingdb/util.go
+++ b/internal/federation/federatingdb/util.go
@@ -28,7 +28,6 @@ import (
"codeberg.org/superseriousbusiness/activity/streams/vocab"
"github.com/superseriousbusiness/gotosocial/internal/ap"
"github.com/superseriousbusiness/gotosocial/internal/config"
- "github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtscontext"
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/id"
@@ -126,83 +125,30 @@ func (f *federatingDB) NewID(ctx context.Context, t vocab.Type) (idURL *url.URL,
return url.Parse(fmt.Sprintf("%s://%s/%s", config.GetProtocol(), config.GetHost(), newID))
}
-// ActorForOutbox fetches the actor's IRI for the given outbox IRI.
+// ActorForOutbox fetches the local actor's IRI for the given outbox IRI.
//
// The library makes this call only after acquiring a lock first.
func (f *federatingDB) ActorForOutbox(ctx context.Context, outboxIRI *url.URL) (actorIRI *url.URL, err error) {
- acct, err := f.getAccountForIRI(ctx, outboxIRI)
+ acct, err := f.state.DB.GetOneAccountByOutboxURI(ctx, outboxIRI.String())
if err != nil {
return nil, err
}
return url.Parse(acct.URI)
}
-// ActorForInbox fetches the actor's IRI for the given outbox IRI.
+// ActorForInbox fetches the local actor's IRI for the given inbox IRI.
//
// The library makes this call only after acquiring a lock first.
func (f *federatingDB) ActorForInbox(ctx context.Context, inboxIRI *url.URL) (actorIRI *url.URL, err error) {
- acct, err := f.getAccountForIRI(ctx, inboxIRI)
+ acct, err := f.state.DB.GetOneAccountByInboxURI(ctx, inboxIRI.String())
if err != nil {
return nil, err
}
return url.Parse(acct.URI)
}
-// getAccountForIRI returns the account that corresponds to or owns the given IRI.
-func (f *federatingDB) getAccountForIRI(ctx context.Context, iri *url.URL) (*gtsmodel.Account, error) {
- var (
- acct *gtsmodel.Account
- err error
- )
-
- switch {
- case uris.IsUserPath(iri):
- if acct, err = f.state.DB.GetAccountByURI(ctx, iri.String()); err != nil {
- if err == db.ErrNoEntries {
- return nil, fmt.Errorf("no actor found that corresponds to uri %s", iri.String())
- }
- return nil, fmt.Errorf("db error searching for actor with uri %s", iri.String())
- }
- return acct, nil
- case uris.IsInboxPath(iri):
- if acct, err = f.state.DB.GetAccountByInboxURI(ctx, iri.String()); err != nil {
- if err == db.ErrNoEntries {
- return nil, fmt.Errorf("no actor found that corresponds to inbox %s", iri.String())
- }
- return nil, fmt.Errorf("db error searching for actor with inbox %s", iri.String())
- }
- return acct, nil
- case uris.IsOutboxPath(iri):
- if acct, err = f.state.DB.GetAccountByOutboxURI(ctx, iri.String()); err != nil {
- if err == db.ErrNoEntries {
- return nil, fmt.Errorf("no actor found that corresponds to outbox %s", iri.String())
- }
- return nil, fmt.Errorf("db error searching for actor with outbox %s", iri.String())
- }
- return acct, nil
- case uris.IsFollowersPath(iri):
- if acct, err = f.state.DB.GetAccountByFollowersURI(ctx, iri.String()); err != nil {
- if err == db.ErrNoEntries {
- return nil, fmt.Errorf("no actor found that corresponds to followers_uri %s", iri.String())
- }
- return nil, fmt.Errorf("db error searching for actor with followers_uri %s", iri.String())
- }
- return acct, nil
- case uris.IsFollowingPath(iri):
- if acct, err = f.state.DB.GetAccountByFollowingURI(ctx, iri.String()); err != nil {
- if err == db.ErrNoEntries {
- return nil, fmt.Errorf("no actor found that corresponds to following_uri %s", iri.String())
- }
- return nil, fmt.Errorf("db error searching for actor with following_uri %s", iri.String())
- }
- return acct, nil
- default:
- return nil, fmt.Errorf("getActorForIRI: iri %s not recognised", iri)
- }
-}
-
// collectFollows takes a slice of iris and converts them into ActivityStreamsCollection of IRIs.
-func (f *federatingDB) collectIRIs(ctx context.Context, iris []*url.URL) (vocab.ActivityStreamsCollection, error) {
+func (f *federatingDB) collectIRIs(_ context.Context, iris []*url.URL) (vocab.ActivityStreamsCollection, error) {
collection := streams.NewActivityStreamsCollection()
items := streams.NewActivityStreamsItemsProperty()
for _, i := range iris {