diff options
author | 2022-05-08 19:49:45 +0200 | |
---|---|---|
committer | 2022-05-08 18:49:45 +0100 | |
commit | 5004e0a9da665ccc0e18cd4075ee636641b71f0a (patch) | |
tree | b7c8269b954ced61afa9fffd7305bd88acca6f8e /vendor/codeberg.org/gruf/go-pools/bufio.go | |
parent | [bugfix] Fix existing bio text showing as HTML (#531) (diff) | |
download | gotosocial-5004e0a9da665ccc0e18cd4075ee636641b71f0a.tar.xz |
[bugfix] Fix remote media pruning failing if media already gone (#548)
* fix error check of prune to allow missing files
* update go-store library, add test for pruning item with db entry but no file
Signed-off-by: kim <grufwub@gmail.com>
* remove now-unneccessary error check
Signed-off-by: kim <grufwub@gmail.com>
Co-authored-by: kim <grufwub@gmail.com>
Diffstat (limited to 'vendor/codeberg.org/gruf/go-pools/bufio.go')
-rw-r--r-- | vendor/codeberg.org/gruf/go-pools/bufio.go | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/vendor/codeberg.org/gruf/go-pools/bufio.go b/vendor/codeberg.org/gruf/go-pools/bufio.go index 8c2ef9730..e22fd6a1c 100644 --- a/vendor/codeberg.org/gruf/go-pools/bufio.go +++ b/vendor/codeberg.org/gruf/go-pools/bufio.go @@ -6,7 +6,7 @@ import ( "sync" ) -// BufioReaderPool is a pooled allocator for bufio.Reader objects +// BufioReaderPool is a pooled allocator for bufio.Reader objects. type BufioReaderPool interface { // Get fetches a bufio.Reader from pool and resets to supplied reader Get(io.Reader) *bufio.Reader @@ -15,32 +15,39 @@ type BufioReaderPool interface { Put(*bufio.Reader) } -// NewBufioReaderPool returns a newly instantiated bufio.Reader pool +// NewBufioReaderPool returns a newly instantiated bufio.Reader pool. func NewBufioReaderPool(size int) BufioReaderPool { return &bufioReaderPool{ - Pool: sync.Pool{ + pool: sync.Pool{ New: func() interface{} { return bufio.NewReaderSize(nil, size) }, }, + size: size, } } -// bufioReaderPool is our implementation of BufioReaderPool -type bufioReaderPool struct{ sync.Pool } +// bufioReaderPool is our implementation of BufioReaderPool. +type bufioReaderPool struct { + pool sync.Pool + size int +} func (p *bufioReaderPool) Get(r io.Reader) *bufio.Reader { - br := p.Pool.Get().(*bufio.Reader) + br := p.pool.Get().(*bufio.Reader) br.Reset(r) return br } func (p *bufioReaderPool) Put(br *bufio.Reader) { + if br.Size() < p.size { + return + } br.Reset(nil) - p.Pool.Put(br) + p.pool.Put(br) } -// BufioWriterPool is a pooled allocator for bufio.Writer objects +// BufioWriterPool is a pooled allocator for bufio.Writer objects. type BufioWriterPool interface { // Get fetches a bufio.Writer from pool and resets to supplied writer Get(io.Writer) *bufio.Writer @@ -49,27 +56,34 @@ type BufioWriterPool interface { Put(*bufio.Writer) } -// NewBufioWriterPool returns a newly instantiated bufio.Writer pool +// NewBufioWriterPool returns a newly instantiated bufio.Writer pool. func NewBufioWriterPool(size int) BufioWriterPool { return &bufioWriterPool{ - Pool: sync.Pool{ + pool: sync.Pool{ New: func() interface{} { return bufio.NewWriterSize(nil, size) }, }, + size: size, } } -// bufioWriterPool is our implementation of BufioWriterPool -type bufioWriterPool struct{ sync.Pool } +// bufioWriterPool is our implementation of BufioWriterPool. +type bufioWriterPool struct { + pool sync.Pool + size int +} func (p *bufioWriterPool) Get(w io.Writer) *bufio.Writer { - bw := p.Pool.Get().(*bufio.Writer) + bw := p.pool.Get().(*bufio.Writer) bw.Reset(w) return bw } func (p *bufioWriterPool) Put(bw *bufio.Writer) { + if bw.Size() < p.size { + return + } bw.Reset(nil) - p.Pool.Put(bw) + p.pool.Put(bw) } |