From a2fca74c3224453a77f048896ab6e2c40f6dc4d8 Mon Sep 17 00:00:00 2001 From: Travis Ralston <travpc@gmail.com> Date: Mon, 21 Aug 2023 20:49:47 -0600 Subject: [PATCH] Don't calculate blurhashes on things we wouldn't thumbnail --- pipelines/_steps/upload/blurhash_async.go | 5 ++++- pipelines/pipeline_upload/pipeline.go | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pipelines/_steps/upload/blurhash_async.go b/pipelines/_steps/upload/blurhash_async.go index ba9d57a2..d44a53c6 100644 --- a/pipelines/_steps/upload/blurhash_async.go +++ b/pipelines/_steps/upload/blurhash_async.go @@ -10,7 +10,7 @@ import ( "github.com/turt2live/matrix-media-repo/database" ) -func CalculateBlurhashAsync(ctx rcontext.RequestContext, reader io.Reader, sha256hash string) chan struct{} { +func CalculateBlurhashAsync(ctx rcontext.RequestContext, reader io.Reader, sizeBytes int64, sha256hash string) chan struct{} { var err error opChan := make(chan struct{}) go func() { @@ -21,6 +21,9 @@ func CalculateBlurhashAsync(ctx rcontext.RequestContext, reader io.Reader, sha25 if !ctx.Config.Features.MSC2448Blurhash.Enabled { return } + if ctx.Config.Thumbnails.MaxSourceBytes <= sizeBytes { + return + } var img image.Image img, err = imaging.Decode(reader) diff --git a/pipelines/pipeline_upload/pipeline.go b/pipelines/pipeline_upload/pipeline.go index ba53322e..66105d7d 100644 --- a/pipelines/pipeline_upload/pipeline.go +++ b/pipelines/pipeline_upload/pipeline.go @@ -150,7 +150,7 @@ func Execute(ctx rcontext.RequestContext, origin string, mediaId string, r io.Re } // Step 10: Asynchronously calculate blurhash - bhChan := upload.CalculateBlurhashAsync(ctx, bhR, sha256hash) + bhChan := upload.CalculateBlurhashAsync(ctx, bhR, sizeBytes, sha256hash) // Step 11: Asynchronously upload to cache cacheChan := upload.PopulateCacheAsync(ctx, cacheR, sizeBytes, sha256hash) -- GitLab