[chore] close in-storage media reader _before_ opening write, no need to leave it hanging around (#1016)
Signed-off-by: kim <grufwub@gmail.com> Signed-off-by: kim <grufwub@gmail.com>
This commit is contained in:
parent
b755906ad1
commit
3ce0e33f99
|
@ -148,12 +148,7 @@ func (p *ProcessingEmoji) loadStatic(ctx context.Context) error {
|
||||||
atomic.StoreInt32(&p.staticState, int32(errored))
|
atomic.StoreInt32(&p.staticState, int32(errored))
|
||||||
return p.err
|
return p.err
|
||||||
}
|
}
|
||||||
|
defer stored.Close()
|
||||||
defer func() {
|
|
||||||
if err := stored.Close(); err != nil {
|
|
||||||
log.Errorf("loadStatic: error closing stored full size: %s", err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// we haven't processed a static version of this emoji yet so do it now
|
// we haven't processed a static version of this emoji yet so do it now
|
||||||
static, err := deriveStaticEmoji(stored, p.emoji.ImageContentType)
|
static, err := deriveStaticEmoji(stored, p.emoji.ImageContentType)
|
||||||
|
@ -163,7 +158,12 @@ func (p *ProcessingEmoji) loadStatic(ctx context.Context) error {
|
||||||
return p.err
|
return p.err
|
||||||
}
|
}
|
||||||
|
|
||||||
// put the static in storage
|
// Close stored emoji now we're done
|
||||||
|
if err := stored.Close(); err != nil {
|
||||||
|
log.Errorf("loadStatic: error closing stored full size: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// put the static image in storage
|
||||||
if err := p.storage.Put(ctx, p.emoji.ImageStaticPath, static.small); err != nil && err != storage.ErrAlreadyExists {
|
if err := p.storage.Put(ctx, p.emoji.ImageStaticPath, static.small); err != nil && err != storage.ErrAlreadyExists {
|
||||||
p.err = fmt.Errorf("loadStatic: error storing static: %s", err)
|
p.err = fmt.Errorf("loadStatic: error storing static: %s", err)
|
||||||
atomic.StoreInt32(&p.staticState, int32(errored))
|
atomic.StoreInt32(&p.staticState, int32(errored))
|
||||||
|
|
|
@ -137,22 +137,15 @@ func (p *ProcessingMedia) loadThumb(ctx context.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// stream the original file out of storage
|
// stream the original file out of storage
|
||||||
log.Tracef("loadThumb: fetching attachment from storage %s", p.attachment.URL)
|
|
||||||
stored, err := p.storage.GetStream(ctx, p.attachment.File.Path)
|
stored, err := p.storage.GetStream(ctx, p.attachment.File.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.err = fmt.Errorf("loadThumb: error fetching file from storage: %s", err)
|
p.err = fmt.Errorf("loadThumb: error fetching file from storage: %s", err)
|
||||||
atomic.StoreInt32(&p.thumbState, int32(errored))
|
atomic.StoreInt32(&p.thumbState, int32(errored))
|
||||||
return p.err
|
return p.err
|
||||||
}
|
}
|
||||||
|
defer stored.Close()
|
||||||
defer func() {
|
|
||||||
if err := stored.Close(); err != nil {
|
|
||||||
log.Errorf("loadThumb: error closing stored full size: %s", err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// stream the file from storage straight into the derive thumbnail function
|
// stream the file from storage straight into the derive thumbnail function
|
||||||
log.Tracef("loadThumb: calling deriveThumbnail %s", p.attachment.URL)
|
|
||||||
thumb, err := deriveThumbnail(stored, p.attachment.File.ContentType, createBlurhash)
|
thumb, err := deriveThumbnail(stored, p.attachment.File.ContentType, createBlurhash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.err = fmt.Errorf("loadThumb: error deriving thumbnail: %s", err)
|
p.err = fmt.Errorf("loadThumb: error deriving thumbnail: %s", err)
|
||||||
|
@ -160,8 +153,12 @@ func (p *ProcessingMedia) loadThumb(ctx context.Context) error {
|
||||||
return p.err
|
return p.err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close stored media now we're done
|
||||||
|
if err := stored.Close(); err != nil {
|
||||||
|
log.Errorf("loadThumb: error closing stored full size: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
// put the thumbnail in storage
|
// put the thumbnail in storage
|
||||||
log.Tracef("loadThumb: storing new thumbnail %s", p.attachment.URL)
|
|
||||||
if err := p.storage.Put(ctx, p.attachment.Thumbnail.Path, thumb.small); err != nil && err != storage.ErrAlreadyExists {
|
if err := p.storage.Put(ctx, p.attachment.Thumbnail.Path, thumb.small); err != nil && err != storage.ErrAlreadyExists {
|
||||||
p.err = fmt.Errorf("loadThumb: error storing thumbnail: %s", err)
|
p.err = fmt.Errorf("loadThumb: error storing thumbnail: %s", err)
|
||||||
atomic.StoreInt32(&p.thumbState, int32(errored))
|
atomic.StoreInt32(&p.thumbState, int32(errored))
|
||||||
|
|
Loading…
Reference in New Issue