[bugfix] Fix multiple "updated_at" columns for media updates (#1660)

* [bugfix] Fix multiple "updated_at" columns for media updates

* silly unrelated race condition
This commit is contained in:
tobi 2023-03-31 15:19:50 +02:00 committed by GitHub
parent d9bbcc60a6
commit 60639a6a0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 9 deletions

View file

@ -328,10 +328,8 @@ func (m *manager) uncacheAttachment(ctx context.Context, attachment *gtsmodel.Me
}
// Update attachment to reflect that we no longer have it cached.
attachment.UpdatedAt = time.Now()
cached := false
attachment.Cached = &cached
return m.state.DB.UpdateAttachment(ctx, attachment, "updated_at", "cached")
attachment.Cached = func() *bool { i := false; return &i }()
return m.state.DB.UpdateAttachment(ctx, attachment, "cached")
}
func (m *manager) removeFiles(ctx context.Context, keys ...string) (int, error) {

View file

@ -88,7 +88,7 @@ func (suite *AccountTestSuite) TestAccountDeleteLocal() {
if !testrig.WaitFor(func() bool {
dbAccount, _ := suite.db.GetAccountByID(ctx, deletingAccount.ID)
return suite.WithinDuration(dbAccount.SuspendedAt, time.Now(), 30*time.Second)
return !dbAccount.SuspendedAt.IsZero()
}) {
suite.FailNow("timed out waiting for account to be deleted")
}

View file

@ -21,7 +21,6 @@ import (
"context"
"errors"
"fmt"
"time"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
"github.com/superseriousbusiness/gotosocial/internal/db"
@ -44,11 +43,9 @@ func (p *Processor) Unattach(ctx context.Context, account *gtsmodel.Account, med
return nil, gtserror.NewErrorNotFound(errors.New("attachment not owned by requesting account"))
}
updatingColumns := []string{"updated_at", "status_id"}
attachment.UpdatedAt = time.Now()
attachment.StatusID = ""
if err := p.state.DB.UpdateAttachment(ctx, attachment, updatingColumns...); err != nil {
if err := p.state.DB.UpdateAttachment(ctx, attachment, "status_id"); err != nil {
return nil, gtserror.NewErrorNotFound(fmt.Errorf("db error updating attachment: %s", err))
}