mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
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:
@@ -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 := >smodel.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 := >smodel.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))
|
||||
|
Reference in New Issue
Block a user