[chore] Migrate accounts to new table, relax uniqueness constraint of actor url and collections

This commit is contained in:
tobi 2025-04-02 12:40:35 +02:00
commit fe352c69b5
37 changed files with 1270 additions and 566 deletions

View file

@ -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)
}
}

View file

@ -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)
}