Pg to bun (#148)

* start moving to bun

* changing more stuff

* more

* and yet more

* tests passing

* seems stable now

* more big changes

* small fix

* little fixes
This commit is contained in:
tobi
2021-08-25 15:34:33 +02:00
committed by GitHub
parent 071eca20ce
commit 2dc9fc1626
713 changed files with 98694 additions and 22704 deletions

View File

@@ -19,6 +19,7 @@
package admin
import (
"context"
"fmt"
"time"
@@ -28,10 +29,10 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
)
func (p *processor) DomainBlockDelete(account *gtsmodel.Account, id string) (*apimodel.DomainBlock, gtserror.WithCode) {
func (p *processor) DomainBlockDelete(ctx context.Context, account *gtsmodel.Account, id string) (*apimodel.DomainBlock, gtserror.WithCode) {
domainBlock := &gtsmodel.DomainBlock{}
if err := p.db.GetByID(id, domainBlock); err != nil {
if err := p.db.GetByID(ctx, id, domainBlock); err != nil {
if err != db.ErrNoEntries {
// something has gone really wrong
return nil, gtserror.NewErrorInternalError(err)
@@ -41,39 +42,39 @@ func (p *processor) DomainBlockDelete(account *gtsmodel.Account, id string) (*ap
}
// prepare the domain block to return
mastoDomainBlock, err := p.tc.DomainBlockToMasto(domainBlock, false)
mastoDomainBlock, err := p.tc.DomainBlockToMasto(ctx, domainBlock, false)
if err != nil {
return nil, gtserror.NewErrorInternalError(err)
}
// delete the domain block
if err := p.db.DeleteByID(id, domainBlock); err != nil {
if err := p.db.DeleteByID(ctx, id, domainBlock); err != nil {
return nil, gtserror.NewErrorInternalError(err)
}
// remove the domain block reference from the instance, if we have an entry for it
i := &gtsmodel.Instance{}
if err := p.db.GetWhere([]db.Where{
if err := p.db.GetWhere(ctx, []db.Where{
{Key: "domain", Value: domainBlock.Domain, CaseInsensitive: true},
{Key: "domain_block_id", Value: id},
}, i); err == nil {
i.SuspendedAt = time.Time{}
i.DomainBlockID = ""
if err := p.db.UpdateByID(i.ID, i); err != nil {
if err := p.db.UpdateByID(ctx, i.ID, i); err != nil {
return nil, gtserror.NewErrorInternalError(fmt.Errorf("couldn't update database entry for instance %s: %s", domainBlock.Domain, err))
}
}
// unsuspend all accounts whose suspension origin was this domain block
// 1. remove the 'suspended_at' entry from their accounts
if err := p.db.UpdateWhere([]db.Where{
if err := p.db.UpdateWhere(ctx, []db.Where{
{Key: "suspension_origin", Value: domainBlock.ID},
}, "suspended_at", nil, &[]*gtsmodel.Account{}); err != nil {
return nil, gtserror.NewErrorInternalError(fmt.Errorf("database error removing suspended_at from accounts: %s", err))
}
// 2. remove the 'suspension_origin' entry from their accounts
if err := p.db.UpdateWhere([]db.Where{
if err := p.db.UpdateWhere(ctx, []db.Where{
{Key: "suspension_origin", Value: domainBlock.ID},
}, "suspension_origin", nil, &[]*gtsmodel.Account{}); err != nil {
return nil, gtserror.NewErrorInternalError(fmt.Errorf("database error removing suspension_origin from accounts: %s", err))