mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-01 10:53:33 -06:00
[chore] Migrate accounts to new table, relax uniqueness constraint of actor url and collections
This commit is contained in:
parent
57c5f68e1a
commit
fe352c69b5
37 changed files with 1270 additions and 566 deletions
|
|
@ -24,6 +24,7 @@ import (
|
|||
"net/url"
|
||||
"time"
|
||||
|
||||
errorsv2 "codeberg.org/gruf/go-errors/v2"
|
||||
"codeberg.org/superseriousbusiness/activity/pub"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/config"
|
||||
|
|
@ -137,12 +138,17 @@ func (d *Dereferencer) getAccountByURI(ctx context.Context, requestUser string,
|
|||
}
|
||||
|
||||
if account == nil {
|
||||
// Else, search the database for existing by URL.
|
||||
account, err = d.state.DB.GetAccountByURL(
|
||||
// Else, search the database for one account with URL.
|
||||
// Can return multiple hits so check for ErrMultipleEntries.
|
||||
account, err = d.state.DB.GetOneAccountByURL(
|
||||
gtscontext.SetBarebones(ctx),
|
||||
uriStr,
|
||||
)
|
||||
if err != nil && !errors.Is(err, db.ErrNoEntries) {
|
||||
if err != nil && !errorsv2.IsV2(
|
||||
err,
|
||||
db.ErrNoEntries,
|
||||
db.ErrMultipleEntries,
|
||||
) {
|
||||
return nil, nil, gtserror.Newf("error checking database for account %s by url: %w", uriStr, err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ func (suite *AccountTestSuite) TestDereferenceGroup() {
|
|||
dbGroup, err := suite.db.GetAccountByURI(context.Background(), group.URI)
|
||||
suite.NoError(err)
|
||||
suite.Equal(group.ID, dbGroup.ID)
|
||||
suite.Equal(ap.ActorGroup, dbGroup.ActorType)
|
||||
suite.Equal(ap.ActorGroup, dbGroup.ActorType.String())
|
||||
}
|
||||
|
||||
func (suite *AccountTestSuite) TestDereferenceService() {
|
||||
|
|
@ -91,7 +91,7 @@ func (suite *AccountTestSuite) TestDereferenceService() {
|
|||
dbService, err := suite.db.GetAccountByURI(context.Background(), service.URI)
|
||||
suite.NoError(err)
|
||||
suite.Equal(service.ID, dbService.ID)
|
||||
suite.Equal(ap.ActorService, dbService.ActorType)
|
||||
suite.Equal(ap.ActorService, dbService.ActorType.String())
|
||||
suite.Equal("example.org", dbService.Domain)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue