diff options
| author | 2025-04-06 14:39:40 +0200 | |
|---|---|---|
| committer | 2025-04-06 14:39:40 +0200 | |
| commit | 8ae2440da3a9b66c379c5a9444b50e758deef61b (patch) | |
| tree | 06b3ba58208434f6ddbd198a396159ac2c4d9c80 /internal/federation/federatingdb/util.go | |
| parent | [feature] Allow deleting avatar + header via settings panel (#3970) (diff) | |
| download | gotosocial-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/util.go')
| -rw-r--r-- | internal/federation/federatingdb/util.go | 64 |
1 files changed, 5 insertions, 59 deletions
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 { |
