mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-09 23:58:07 -06:00
[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
This commit is contained in:
parent
52fe681ba2
commit
ac6ed3d939
376 changed files with 337942 additions and 298092 deletions
|
|
@ -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 := >smodel.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 {
|
||||
|
|
|
|||
|
|
@ -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 := >smodel.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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue