Browse Source

Check timeout automatically

DarthSim 3 years ago
parent
commit
a44e8dc94b

+ 2 - 2
processing/apply_filters.go

@@ -12,7 +12,7 @@ func applyFilters(pctx *pipelineContext, img *vips.Image, po *options.Processing
 		return nil
 	}
 
-	if err := copyMemoryAndCheckTimeout(pctx.ctx, img); err != nil {
+	if err := img.CopyMemory(); err != nil {
 		return err
 	}
 
@@ -52,5 +52,5 @@ func applyFilters(pctx *pipelineContext, img *vips.Image, po *options.Processing
 		return err
 	}
 
-	return copyMemoryAndCheckTimeout(pctx.ctx, img)
+	return img.CopyMemory()
 }

+ 0 - 14
processing/copy_and_check_timeout.go

@@ -1,14 +0,0 @@
-package processing
-
-import (
-	"context"
-
-	"github.com/imgproxy/imgproxy/v3/router"
-	"github.com/imgproxy/imgproxy/v3/vips"
-)
-
-func copyMemoryAndCheckTimeout(ctx context.Context, img *vips.Image) error {
-	err := img.CopyMemory()
-	router.CheckTimeout(ctx)
-	return err
-}

+ 1 - 1
processing/finalize.go

@@ -106,5 +106,5 @@ func finalize(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOpti
 		}
 	}
 
-	return copyMemoryAndCheckTimeout(pctx.ctx, img)
+	return img.CopyMemory()
 }

+ 1 - 1
processing/fix_webp_size.go

@@ -29,5 +29,5 @@ func fixWebpSize(pctx *pipelineContext, img *vips.Image, po *options.ProcessingO
 
 	log.Warningf("WebP dimension size is limited to %d. The image is rescaled to %dx%d", int(webpMaxDimension), img.Width(), img.Height())
 
-	return copyMemoryAndCheckTimeout(pctx.ctx, img)
+	return img.CopyMemory()
 }

+ 2 - 0
processing/pipeline.go

@@ -6,6 +6,7 @@ import (
 	"github.com/imgproxy/imgproxy/v3/imagedata"
 	"github.com/imgproxy/imgproxy/v3/imagetype"
 	"github.com/imgproxy/imgproxy/v3/options"
+	"github.com/imgproxy/imgproxy/v3/router"
 	"github.com/imgproxy/imgproxy/v3/vips"
 )
 
@@ -52,6 +53,7 @@ func (p pipeline) Run(ctx context.Context, img *vips.Image, po *options.Processi
 		if err := step(&pctx, img, po, imgdata); err != nil {
 			return err
 		}
+		router.CheckTimeout(ctx)
 	}
 
 	return nil

+ 1 - 5
processing/processing.go

@@ -140,7 +140,7 @@ func transformAnimated(ctx context.Context, img *vips.Image, po *options.Process
 		return err
 	}
 
-	if err = copyMemoryAndCheckTimeout(ctx, img); err != nil {
+	if err = img.CopyMemory(); err != nil {
 		return err
 	}
 
@@ -264,10 +264,6 @@ func ProcessImage(ctx context.Context, imgdata *imagedata.ImageData, po *options
 		}
 	}
 
-	if err := copyMemoryAndCheckTimeout(ctx, img); err != nil {
-		return nil, err
-	}
-
 	if po.Format == imagetype.AVIF && (img.Width() < 16 || img.Height() < 16) {
 		if img.HasAlpha() {
 			po.Format = imagetype.PNG

+ 1 - 1
processing/scale.go

@@ -18,5 +18,5 @@ func scale(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOptions
 		}
 	}
 
-	return copyMemoryAndCheckTimeout(pctx.ctx, img)
+	return img.CopyMemory()
 }

+ 1 - 1
processing/trim.go

@@ -14,7 +14,7 @@ func trim(pctx *pipelineContext, img *vips.Image, po *options.ProcessingOptions,
 	if err := img.Trim(po.Trim.Threshold, po.Trim.Smart, po.Trim.Color, po.Trim.EqualHor, po.Trim.EqualVer); err != nil {
 		return err
 	}
-	if err := copyMemoryAndCheckTimeout(pctx.ctx, img); err != nil {
+	if err := img.CopyMemory(); err != nil {
 		return err
 	}