mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-02 07:52:25 -06:00
[chore] media and emoji refactoring (#3000)
* start updating media manager interface ready for storing attachments / emoji right away
* store emoji and media as uncached immediately, then (re-)cache on Processing{}.Load()
* remove now unused media workers
* fix tests and issues
* fix another test!
* fix emoji activitypub uri setting behaviour, fix remainder of test compilation issues
* fix more tests
* fix (most of) remaining tests, add debouncing to repeatedly failing media / emojis
* whoops, rebase issue
* remove kim's whacky experiments
* do some reshuffling, ensure emoji uri gets set
* ensure marked as not cached on cleanup
* tweaks to media / emoji processing to handle context canceled better
* ensure newly fetched emojis actually get set in returned slice
* use different varnames to be a bit more obvious
* move emoji refresh rate limiting to dereferencer
* add exported dereferencer functions for remote media, use these for recaching in processor
* add check for nil attachment in updateAttachment()
* remove unused emoji and media fields + columns
* see previous commit
* fix old migrations expecting image_updated_at to exists (from copies of old models)
* remove freshness checking code (seems to be broken...)
* fix error arg causing nil ptr exception
* finish documentating functions with comments, slight tweaks to media / emoji deref error logic
* remove some extra unneeded boolean checking
* finish writing documentation (code comments) for exported media manager methods
* undo changes to migration snapshot gtsmodels, updated failing migration to have its own snapshot
* move doesColumnExist() to util.go in migrations package
This commit is contained in:
parent
fa710057c8
commit
21bb324156
48 changed files with 2578 additions and 1926 deletions
|
|
@ -43,12 +43,9 @@ var (
|
|||
BufferPool: &pngEncoderBufferPool{},
|
||||
}
|
||||
|
||||
// jpegBufferPool is a memory pool of byte buffers for JPEG encoding.
|
||||
jpegBufferPool = sync.Pool{
|
||||
New: func() any {
|
||||
return bufio.NewWriter(nil)
|
||||
},
|
||||
}
|
||||
// jpegBufferPool is a memory pool
|
||||
// of byte buffers for JPEG encoding.
|
||||
jpegBufferPool sync.Pool
|
||||
)
|
||||
|
||||
// gtsImage is a thin wrapper around the standard library image
|
||||
|
|
@ -80,25 +77,29 @@ func decodeImage(r io.Reader, opts ...imaging.DecodeOption) (*gtsImage, error) {
|
|||
}
|
||||
|
||||
// Width returns the image width in pixels.
|
||||
func (m *gtsImage) Width() uint32 {
|
||||
return uint32(m.image.Bounds().Size().X)
|
||||
func (m *gtsImage) Width() int {
|
||||
return m.image.Bounds().Size().X
|
||||
}
|
||||
|
||||
// Height returns the image height in pixels.
|
||||
func (m *gtsImage) Height() uint32 {
|
||||
return uint32(m.image.Bounds().Size().Y)
|
||||
func (m *gtsImage) Height() int {
|
||||
return m.image.Bounds().Size().Y
|
||||
}
|
||||
|
||||
// Size returns the total number of image pixels.
|
||||
func (m *gtsImage) Size() uint64 {
|
||||
return uint64(m.image.Bounds().Size().X) *
|
||||
uint64(m.image.Bounds().Size().Y)
|
||||
func (m *gtsImage) Size() int {
|
||||
return m.image.Bounds().Size().X *
|
||||
m.image.Bounds().Size().Y
|
||||
}
|
||||
|
||||
// AspectRatio returns the image ratio of width:height.
|
||||
func (m *gtsImage) AspectRatio() float32 {
|
||||
return float32(m.image.Bounds().Size().X) /
|
||||
float32(m.image.Bounds().Size().Y)
|
||||
|
||||
// note: we cast bounds to float64 to prevent truncation
|
||||
// and only at the end aspect ratio do we cast to float32
|
||||
// (as the sizes are likely to be much larger than ratio).
|
||||
return float32(float64(m.image.Bounds().Size().X) /
|
||||
float64(m.image.Bounds().Size().Y))
|
||||
}
|
||||
|
||||
// Thumbnail returns a small sized copy of gtsImage{}, limited to 512x512 if not small enough.
|
||||
|
|
@ -160,7 +161,11 @@ func (m *gtsImage) ToPNG() io.Reader {
|
|||
|
||||
// getJPEGBuffer fetches a reset JPEG encoding buffer from global JPEG buffer pool.
|
||||
func getJPEGBuffer(w io.Writer) *bufio.Writer {
|
||||
buf, _ := jpegBufferPool.Get().(*bufio.Writer)
|
||||
v := jpegBufferPool.Get()
|
||||
if v == nil {
|
||||
v = bufio.NewWriter(nil)
|
||||
}
|
||||
buf := v.(*bufio.Writer)
|
||||
buf.Reset(w)
|
||||
return buf
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue