summaryrefslogtreecommitdiff
path: root/internal/media
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2022-08-15 12:35:05 +0200
committerLibravatar GitHub <noreply@github.com>2022-08-15 11:35:05 +0100
commitac6ed3d939fe9dad81aadbd04541e905c625ca82 (patch)
tree6116baf25675837dc99f69c49b9fec2ff112ce5c /internal/media
parent[frontend] Sensitive media spoilers (#752) (diff)
downloadgotosocial-ac6ed3d939fe9dad81aadbd04541e905c625ca82.tar.xz
[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
Diffstat (limited to 'internal/media')
-rw-r--r--internal/media/processingemoji.go11
-rw-r--r--internal/media/processingmedia.go18
-rw-r--r--internal/media/prunemeta.go4
-rw-r--r--internal/media/prunemeta_test.go8
-rw-r--r--internal/media/pruneremote.go16
-rw-r--r--internal/media/pruneremote_test.go8
-rw-r--r--internal/media/pruneunusedlocal_test.go4
7 files changed, 44 insertions, 25 deletions
diff --git a/internal/media/processingemoji.go b/internal/media/processingemoji.go
index b28dc7f02..098d0aa19 100644
--- a/internal/media/processingemoji.go
+++ b/internal/media/processingemoji.go
@@ -230,6 +230,9 @@ func (m *manager) preProcessEmoji(ctx context.Context, data DataFunc, postData P
return nil, fmt.Errorf("preProcessEmoji: error fetching this instance account from the db: %s", err)
}
+ disabled := false
+ visibleInPicker := true
+
// populate initial fields on the emoji -- some of these will be overwritten as we proceed
emoji := &gtsmodel.Emoji{
ID: id,
@@ -248,9 +251,9 @@ func (m *manager) preProcessEmoji(ctx context.Context, data DataFunc, postData P
ImageFileSize: 0,
ImageStaticFileSize: 0,
ImageUpdatedAt: time.Now(),
- Disabled: false,
+ Disabled: &disabled,
URI: uri,
- VisibleInPicker: true,
+ VisibleInPicker: &visibleInPicker,
CategoryID: "",
}
@@ -274,11 +277,11 @@ func (m *manager) preProcessEmoji(ctx context.Context, data DataFunc, postData P
}
if ai.Disabled != nil {
- emoji.Disabled = *ai.Disabled
+ emoji.Disabled = ai.Disabled
}
if ai.VisibleInPicker != nil {
- emoji.VisibleInPicker = *ai.VisibleInPicker
+ emoji.VisibleInPicker = ai.VisibleInPicker
}
if ai.CategoryID != nil {
diff --git a/internal/media/processingmedia.go b/internal/media/processingmedia.go
index 885e97417..914d6d276 100644
--- a/internal/media/processingmedia.go
+++ b/internal/media/processingmedia.go
@@ -346,7 +346,9 @@ func (p *ProcessingMedia) store(ctx context.Context) error {
if err := p.storage.PutStream(ctx, p.attachment.File.Path, clean); err != nil {
return fmt.Errorf("store: error storing stream: %s", err)
}
- p.attachment.Cached = true
+
+ cached := true
+ p.attachment.Cached = &cached
p.read = true
if p.postData != nil {
@@ -376,6 +378,10 @@ func (m *manager) preProcessMedia(ctx context.Context, data DataFunc, postData P
UpdatedAt: time.Now(),
}
+ avatar := false
+ header := false
+ cached := false
+
// populate initial fields on the media attachment -- some of these will be overwritten as we proceed
attachment := &gtsmodel.MediaAttachment{
ID: id,
@@ -393,9 +399,9 @@ func (m *manager) preProcessMedia(ctx context.Context, data DataFunc, postData P
Processing: gtsmodel.ProcessingStatusReceived,
File: file,
Thumbnail: thumbnail,
- Avatar: false,
- Header: false,
- Cached: false,
+ Avatar: &avatar,
+ Header: &header,
+ Cached: &cached,
}
// check if we have additional info to add to the attachment,
@@ -426,11 +432,11 @@ func (m *manager) preProcessMedia(ctx context.Context, data DataFunc, postData P
}
if ai.Avatar != nil {
- attachment.Avatar = *ai.Avatar
+ attachment.Avatar = ai.Avatar
}
if ai.Header != nil {
- attachment.Header = *ai.Header
+ attachment.Header = ai.Header
}
if ai.FocusX != nil {
diff --git a/internal/media/prunemeta.go b/internal/media/prunemeta.go
index 7b2b14f98..63bdb00b5 100644
--- a/internal/media/prunemeta.go
+++ b/internal/media/prunemeta.go
@@ -46,8 +46,8 @@ func (m *manager) PruneAllMeta(ctx context.Context) (int, error) {
// - is an avatar but isn't the owning account's current avatar
for _, attachment := range attachments {
if attachment.Account == nil ||
- (attachment.Header && attachment.ID != attachment.Account.HeaderMediaAttachmentID) ||
- (attachment.Avatar && attachment.ID != attachment.Account.AvatarMediaAttachmentID) {
+ (*attachment.Header && attachment.ID != attachment.Account.HeaderMediaAttachmentID) ||
+ (*attachment.Avatar && attachment.ID != attachment.Account.AvatarMediaAttachmentID) {
if err := m.pruneOneAvatarOrHeader(ctx, attachment); err != nil {
return totalPruned, err
}
diff --git a/internal/media/prunemeta_test.go b/internal/media/prunemeta_test.go
index b02156587..32a3b9a5c 100644
--- a/internal/media/prunemeta_test.go
+++ b/internal/media/prunemeta_test.go
@@ -40,7 +40,7 @@ func (suite *PruneMetaTestSuite) TestPruneMeta() {
zork := suite.testAccounts["local_account_1"]
zork.AvatarMediaAttachmentID = ""
zork.HeaderMediaAttachmentID = ""
- if err := suite.db.UpdateByPrimaryKey(ctx, zork); err != nil {
+ if err := suite.db.UpdateByPrimaryKey(ctx, zork, "avatar_media_attachment_id", "header_media_attachment_id"); err != nil {
panic(err)
}
@@ -72,7 +72,7 @@ func (suite *PruneMetaTestSuite) TestPruneMetaTwice() {
zork := suite.testAccounts["local_account_1"]
zork.AvatarMediaAttachmentID = ""
zork.HeaderMediaAttachmentID = ""
- if err := suite.db.UpdateByPrimaryKey(ctx, zork); err != nil {
+ if err := suite.db.UpdateByPrimaryKey(ctx, zork, "avatar_media_attachment_id", "header_media_attachment_id"); err != nil {
panic(err)
}
@@ -95,14 +95,14 @@ func (suite *PruneMetaTestSuite) TestPruneMetaMultipleAccounts() {
zork := suite.testAccounts["local_account_1"]
zork.AvatarMediaAttachmentID = ""
zork.HeaderMediaAttachmentID = ""
- if err := suite.db.UpdateByPrimaryKey(ctx, zork); err != nil {
+ if err := suite.db.UpdateByPrimaryKey(ctx, zork, "avatar_media_attachment_id", "header_media_attachment_id"); err != nil {
panic(err)
}
// set zork's unused header as belonging to turtle
turtle := suite.testAccounts["local_account_1"]
zorkOldHeader.AccountID = turtle.ID
- if err := suite.db.UpdateByPrimaryKey(ctx, zorkOldHeader); err != nil {
+ if err := suite.db.UpdateByPrimaryKey(ctx, zorkOldHeader, "account_id"); err != nil {
panic(err)
}
diff --git a/internal/media/pruneremote.go b/internal/media/pruneremote.go
index 5c3335511..43ce53cdc 100644
--- a/internal/media/pruneremote.go
+++ b/internal/media/pruneremote.go
@@ -64,13 +64,17 @@ func (m *manager) PruneAllRemote(ctx context.Context, olderThanDays int) (int, e
}
func (m *manager) pruneOneRemote(ctx context.Context, attachment *gtsmodel.MediaAttachment) error {
+ var changed bool
+
if attachment.File.Path != "" {
// delete the full size attachment from storage
log.Tracef("pruneOneRemote: deleting %s", attachment.File.Path)
if err := m.storage.Delete(ctx, attachment.File.Path); err != nil && err != storage.ErrNotFound {
return err
}
- attachment.Cached = false
+ cached := false
+ attachment.Cached = &cached
+ changed = true
}
if attachment.Thumbnail.Path != "" {
@@ -79,9 +83,15 @@ func (m *manager) pruneOneRemote(ctx context.Context, attachment *gtsmodel.Media
if err := m.storage.Delete(ctx, attachment.Thumbnail.Path); err != nil && err != storage.ErrNotFound {
return err
}
- attachment.Cached = false
+ cached := false
+ attachment.Cached = &cached
+ changed = true
}
// update the attachment to reflect that we no longer have it cached
- return m.db.UpdateByPrimaryKey(ctx, attachment)
+ if changed {
+ return m.db.UpdateByPrimaryKey(ctx, attachment, "updated_at", "cached")
+ }
+
+ return nil
}
diff --git a/internal/media/pruneremote_test.go b/internal/media/pruneremote_test.go
index f5ed8a618..ddf4cb568 100644
--- a/internal/media/pruneremote_test.go
+++ b/internal/media/pruneremote_test.go
@@ -35,7 +35,7 @@ type PruneRemoteTestSuite struct {
func (suite *PruneRemoteTestSuite) TestPruneRemote() {
testAttachment := suite.testAttachments["remote_account_1_status_1_attachment_1"]
- suite.True(testAttachment.Cached)
+ suite.True(*testAttachment.Cached)
totalPruned, err := suite.manager.PruneAllRemote(context.Background(), 1)
suite.NoError(err)
@@ -45,7 +45,7 @@ func (suite *PruneRemoteTestSuite) TestPruneRemote() {
suite.NoError(err)
// the media should no longer be cached
- suite.False(prunedAttachment.Cached)
+ suite.False(*prunedAttachment.Cached)
}
func (suite *PruneRemoteTestSuite) TestPruneRemoteTwice() {
@@ -91,7 +91,7 @@ func (suite *PruneRemoteTestSuite) TestPruneAndRecache() {
suite.NotNil(recachedAttachment)
// recachedAttachment should be basically the same as the old attachment
- suite.True(recachedAttachment.Cached)
+ suite.True(*recachedAttachment.Cached)
suite.Equal(testAttachment.ID, recachedAttachment.ID)
suite.Equal(testAttachment.File.Path, recachedAttachment.File.Path) // file should be stored in the same place
suite.Equal(testAttachment.Thumbnail.Path, recachedAttachment.Thumbnail.Path) // as should the thumbnail
@@ -111,7 +111,7 @@ func (suite *PruneRemoteTestSuite) TestPruneOneNonExistent() {
// Delete this attachment cached on disk
media, err := suite.db.GetAttachmentByID(ctx, testAttachment.ID)
suite.NoError(err)
- suite.True(media.Cached)
+ suite.True(*media.Cached)
err = suite.storage.Delete(ctx, media.File.Path)
suite.NoError(err)
diff --git a/internal/media/pruneunusedlocal_test.go b/internal/media/pruneunusedlocal_test.go
index 976a6226c..d1424a4c9 100644
--- a/internal/media/pruneunusedlocal_test.go
+++ b/internal/media/pruneunusedlocal_test.go
@@ -32,7 +32,7 @@ type PruneUnusedLocalTestSuite struct {
func (suite *PruneUnusedLocalTestSuite) TestPruneUnusedLocal() {
testAttachment := suite.testAttachments["local_account_1_unattached_1"]
- suite.True(testAttachment.Cached)
+ suite.True(*testAttachment.Cached)
totalPruned, err := suite.manager.PruneUnusedLocalAttachments(context.Background())
suite.NoError(err)
@@ -60,7 +60,7 @@ func (suite *PruneUnusedLocalTestSuite) TestPruneOneNonExistent() {
// Delete this attachment cached on disk
media, err := suite.db.GetAttachmentByID(ctx, testAttachment.ID)
suite.NoError(err)
- suite.True(media.Cached)
+ suite.True(*media.Cached)
err = suite.storage.Delete(ctx, media.File.Path)
suite.NoError(err)