From ac6ed3d939fe9dad81aadbd04541e905c625ca82 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Mon, 15 Aug 2022 12:35:05 +0200 Subject: [chore] Update bun / sqlite versions; update gtsmodels (#754) * upstep bun and sqlite versions * allow specific columns to be updated in the db * only update necessary columns for user * bit tidier * only update necessary fields of media_attachment * only update relevant instance fields * update tests * update only specific account columns * use bool pointers on gtsmodels includes attachment, status, account, user * update columns more selectively * test all default fields on new account insert * updating remaining bools on gtsmodels * initialize pointer fields when extracting AP emoji * copy bools properly * add copyBoolPtr convenience function + test it * initialize false bool ptrs a bit more neatly --- internal/processing/media/getfile.go | 4 ++-- internal/processing/media/getfile_test.go | 17 +++++++++-------- internal/processing/media/unattach.go | 3 ++- internal/processing/media/unattach_test.go | 2 +- internal/processing/media/update.go | 14 ++++++++------ 5 files changed, 22 insertions(+), 18 deletions(-) (limited to 'internal/processing/media') diff --git a/internal/processing/media/getfile.go b/internal/processing/media/getfile.go index 3227cb8c8..52cdcc052 100644 --- a/internal/processing/media/getfile.go +++ b/internal/processing/media/getfile.go @@ -112,7 +112,7 @@ func (p *processor) getAttachmentContent(ctx context.Context, requestingAccount } // if we have the media cached on our server already, we can now simply return it from storage - if a.Cached { + if *a.Cached { return p.retrieveFromStorage(ctx, storagePath, attachmentContent) } @@ -236,7 +236,7 @@ func (p *processor) getEmojiContent(ctx context.Context, wantedEmojiID string, e return nil, gtserror.NewErrorNotFound(fmt.Errorf("emoji %s could not be taken from the db: %s", wantedEmojiID, err)) } - if e.Disabled { + if *e.Disabled { return nil, gtserror.NewErrorNotFound(fmt.Errorf("emoji %s has been disabled", wantedEmojiID)) } diff --git a/internal/processing/media/getfile_test.go b/internal/processing/media/getfile_test.go index 7c6525abe..6ba06426f 100644 --- a/internal/processing/media/getfile_test.go +++ b/internal/processing/media/getfile_test.go @@ -28,6 +28,7 @@ import ( "github.com/stretchr/testify/suite" apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" "github.com/superseriousbusiness/gotosocial/internal/media" + "github.com/superseriousbusiness/gotosocial/testrig" ) type GetFileTestSuite struct { @@ -67,8 +68,8 @@ func (suite *GetFileTestSuite) TestGetRemoteFileUncached() { // uncache the file from local testAttachment := suite.testAttachments["remote_account_1_status_1_attachment_1"] - testAttachment.Cached = false - err := suite.db.UpdateByPrimaryKey(ctx, testAttachment) + testAttachment.Cached = testrig.FalseBool() + err := suite.db.UpdateByPrimaryKey(ctx, testAttachment, "cached") suite.NoError(err) err = suite.storage.Delete(ctx, testAttachment.File.Path) suite.NoError(err) @@ -103,7 +104,7 @@ func (suite *GetFileTestSuite) TestGetRemoteFileUncached() { // the attachment should be updated in the database dbAttachment, err := suite.db.GetAttachmentByID(ctx, testAttachment.ID) suite.NoError(err) - suite.True(dbAttachment.Cached) + suite.True(*dbAttachment.Cached) // the file should be back in storage at the same path as before refreshedBytes, err := suite.storage.Get(ctx, testAttachment.File.Path) @@ -116,8 +117,8 @@ func (suite *GetFileTestSuite) TestGetRemoteFileUncachedInterrupted() { // uncache the file from local testAttachment := suite.testAttachments["remote_account_1_status_1_attachment_1"] - testAttachment.Cached = false - err := suite.db.UpdateByPrimaryKey(ctx, testAttachment) + testAttachment.Cached = testrig.FalseBool() + err := suite.db.UpdateByPrimaryKey(ctx, testAttachment, "cached") suite.NoError(err) err = suite.storage.Delete(ctx, testAttachment.File.Path) suite.NoError(err) @@ -153,7 +154,7 @@ func (suite *GetFileTestSuite) TestGetRemoteFileUncachedInterrupted() { // the attachment should still be updated in the database even though the caller hung up dbAttachment, err := suite.db.GetAttachmentByID(ctx, testAttachment.ID) suite.NoError(err) - suite.True(dbAttachment.Cached) + suite.True(*dbAttachment.Cached) // the file should be back in storage at the same path as before refreshedBytes, err := suite.storage.Get(ctx, testAttachment.File.Path) @@ -170,8 +171,8 @@ func (suite *GetFileTestSuite) TestGetRemoteFileThumbnailUncached() { suite.NoError(err) // uncache the file from local - testAttachment.Cached = false - err = suite.db.UpdateByPrimaryKey(ctx, testAttachment) + testAttachment.Cached = testrig.FalseBool() + err = suite.db.UpdateByPrimaryKey(ctx, testAttachment, "cached") suite.NoError(err) err = suite.storage.Delete(ctx, testAttachment.File.Path) suite.NoError(err) diff --git a/internal/processing/media/unattach.go b/internal/processing/media/unattach.go index bb09525fe..5ef8f81f4 100644 --- a/internal/processing/media/unattach.go +++ b/internal/processing/media/unattach.go @@ -43,10 +43,11 @@ 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.db.UpdateByPrimaryKey(ctx, attachment); err != nil { + if err := p.db.UpdateByPrimaryKey(ctx, attachment, updatingColumns...); err != nil { return nil, gtserror.NewErrorNotFound(fmt.Errorf("db error updating attachment: %s", err)) } diff --git a/internal/processing/media/unattach_test.go b/internal/processing/media/unattach_test.go index 60efc2688..7572741ac 100644 --- a/internal/processing/media/unattach_test.go +++ b/internal/processing/media/unattach_test.go @@ -30,7 +30,7 @@ type UnattachTestSuite struct { MediaStandardTestSuite } -func (suite *GetFileTestSuite) TestUnattachMedia() { +func (suite *UnattachTestSuite) TestUnattachMedia() { ctx := context.Background() testAttachment := suite.testAttachments["admin_account_status_1_attachment_1"] diff --git a/internal/processing/media/update.go b/internal/processing/media/update.go index 116588a48..b8177eeb4 100644 --- a/internal/processing/media/update.go +++ b/internal/processing/media/update.go @@ -44,11 +44,11 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, media return nil, gtserror.NewErrorNotFound(errors.New("attachment not owned by requesting account")) } + updatingColumns := []string{} + if form.Description != nil { attachment.Description = text.SanitizePlaintext(*form.Description) - if err := p.db.UpdateByPrimaryKey(ctx, attachment); err != nil { - return nil, gtserror.NewErrorInternalError(fmt.Errorf("database error updating description: %s", err)) - } + updatingColumns = append(updatingColumns, "description") } if form.Focus != nil { @@ -58,9 +58,11 @@ func (p *processor) Update(ctx context.Context, account *gtsmodel.Account, media } attachment.FileMeta.Focus.X = focusx attachment.FileMeta.Focus.Y = focusy - if err := p.db.UpdateByPrimaryKey(ctx, attachment); err != nil { - return nil, gtserror.NewErrorInternalError(fmt.Errorf("database error updating focus: %s", err)) - } + updatingColumns = append(updatingColumns, "focus_x", "focus_y") + } + + if err := p.db.UpdateByPrimaryKey(ctx, attachment, updatingColumns...); err != nil { + return nil, gtserror.NewErrorInternalError(fmt.Errorf("database error updating media: %s", err)) } a, err := p.tc.AttachmentToAPIAttachment(ctx, attachment) -- cgit v1.2.3