diff options
author | 2022-01-15 17:36:15 +0100 | |
---|---|---|
committer | 2022-01-15 17:36:15 +0100 | |
commit | 6bf39d0fc1286bdf2f4760adab52c6eff234d01d (patch) | |
tree | e4916598a7a14eab4336909c5fec1de6ed8ad0d4 /internal/media | |
parent | start fixing up emoji processing code (diff) | |
download | gotosocial-6bf39d0fc1286bdf2f4760adab52c6eff234d01d.tar.xz |
emoji code passing muster
Diffstat (limited to 'internal/media')
-rw-r--r-- | internal/media/processingemoji.go | 22 | ||||
-rw-r--r-- | internal/media/processingmedia.go | 25 |
2 files changed, 27 insertions, 20 deletions
diff --git a/internal/media/processingemoji.go b/internal/media/processingemoji.go index eeccdb281..467b500fc 100644 --- a/internal/media/processingemoji.go +++ b/internal/media/processingemoji.go @@ -72,6 +72,9 @@ type ProcessingEmoji struct { storage *kv.KVStore err error // error created during processing, if any + + // track whether this emoji has already been put in the databse + insertedInDB bool } // EmojiID returns the ID of the underlying emoji without blocking processing. @@ -94,6 +97,16 @@ func (p *ProcessingEmoji) LoadEmoji(ctx context.Context) (*gtsmodel.Emoji, error return nil, err } + // store the result in the database before returning it + p.mu.Lock() + defer p.mu.Unlock() + if !p.insertedInDB { + if err := p.database.Put(ctx, p.emoji); err != nil { + return nil, err + } + p.insertedInDB = true + } + return p.emoji, nil } @@ -127,13 +140,6 @@ func (p *ProcessingEmoji) loadStatic(ctx context.Context) (*ImageMeta, error) { // set appropriate fields on the emoji based on the static version we derived p.emoji.ImageStaticFileSize = len(static.image) - // update the emoji in the db - if err := putOrUpdate(ctx, p.database, p.emoji); err != nil { - p.err = err - p.staticState = errored - return nil, err - } - // set the static on the processing emoji p.static = static @@ -197,7 +203,7 @@ func (p *ProcessingEmoji) loadFullSize(ctx context.Context) (*ImageMeta, error) } // fetchRawData calls the data function attached to p if it hasn't been called yet, -// and updates the underlying attachment fields as necessary. +// and updates the underlying emoji fields as necessary. // It should only be called from within a function that already has a lock on p! func (p *ProcessingEmoji) fetchRawData(ctx context.Context) error { // check if we've already done this and bail early if we have diff --git a/internal/media/processingmedia.go b/internal/media/processingmedia.go index 1bfd7b629..fade64c24 100644 --- a/internal/media/processingmedia.go +++ b/internal/media/processingmedia.go @@ -70,6 +70,9 @@ type ProcessingMedia struct { storage *kv.KVStore err error // error created during processing, if any + + // track whether this media has already been put in the databse + insertedInDB bool } // AttachmentID returns the ID of the underlying media attachment without blocking processing. @@ -92,6 +95,16 @@ func (p *ProcessingMedia) LoadAttachment(ctx context.Context) (*gtsmodel.MediaAt return nil, err } + // store the result in the database before returning it + p.mu.Lock() + defer p.mu.Unlock() + if !p.insertedInDB { + if err := p.database.Put(ctx, p.attachment); err != nil { + return nil, err + } + p.insertedInDB = true + } + return p.attachment, nil } @@ -143,12 +156,6 @@ func (p *ProcessingMedia) loadThumb(ctx context.Context) (*ImageMeta, error) { } p.attachment.Thumbnail.FileSize = len(thumb.image) - if err := putOrUpdate(ctx, p.database, p.attachment); err != nil { - p.err = err - p.thumbstate = errored - return nil, err - } - // set the thumbnail of this media p.thumb = thumb @@ -216,12 +223,6 @@ func (p *ProcessingMedia) loadFullSize(ctx context.Context) (*ImageMeta, error) p.attachment.File.UpdatedAt = time.Now() p.attachment.Processing = gtsmodel.ProcessingStatusProcessed - if err := putOrUpdate(ctx, p.database, p.attachment); err != nil { - p.err = err - p.fullSizeState = errored - return nil, err - } - // set the fullsize of this media p.fullSize = decoded |