From 322508f6d197df9d0f7a7d380a8346518329259b Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Fri, 1 Sep 2023 13:46:51 +0300 Subject: [PATCH] registered a custom Deflate compressor to speedup the backups generation --- CHANGELOG.md | 3 +++ tools/archive/create.go | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0440307c..ac91b713 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,6 +46,9 @@ @hourly - "0 * * * *" ``` +- Registered a custom Deflate compressor to speedup the backups generation. + _Based on several local tests, `pb_data` of ~500MB (from which ~350MB+ are several hundred small files) results in a ~280MB zip generated for ~11s (previously was ~250MB but for ~35s)._ + - (@todo update docs examples) To minimize the footguns with `Dao.FindFirstRecordByFilter()` and `Dao.FindRecordsByFilter()`, the functions now supports an optional placeholder params argument that is safe to be populated with untrusted user input. The placeholders are in the same format as when binding regular SQL parameters. ```go diff --git a/tools/archive/create.go b/tools/archive/create.go index e9e98e69..4907fbbe 100644 --- a/tools/archive/create.go +++ b/tools/archive/create.go @@ -2,6 +2,7 @@ package archive import ( "archive/zip" + "compress/flate" "io" "io/fs" "os" @@ -27,6 +28,11 @@ func Create(src string, dest string, skipPaths ...string) error { zw := zip.NewWriter(zf) defer zw.Close() + // register a custom Deflate compressor + zw.RegisterCompressor(zip.Deflate, func(out io.Writer) (io.WriteCloser, error) { + return flate.NewWriter(out, flate.BestSpeed) + }) + if err := zipAddFS(zw, os.DirFS(src), skipPaths...); err != nil { // try to cleanup at least the created zip file os.Remove(dest)