[#1060] writecache: compress big object if needed

Small objects use `blobstor.Put`, so no changes are required.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-01-11 14:33:04 +03:00 committed by Alex Vanin
parent 0d969d7a06
commit 486d5c2e86
5 changed files with 36 additions and 12 deletions

View file

@ -34,10 +34,14 @@ func (b *BlobStor) Put(prm *PutPrm) (*PutRes, error) {
return nil, fmt.Errorf("could not marshal the object: %w", err)
}
return b.PutRaw(prm.obj.Address(), data, b.needsCompression(prm.obj))
return b.PutRaw(prm.obj.Address(), data, b.NeedsCompression(prm.obj))
}
func (b *BlobStor) needsCompression(obj *object.Object) bool {
// NeedsCompression returns true if object should be compressed.
// For object to be compressed 2 conditions must hold:
// 1. Compression is enabled in settings.
// 2. Object MIME Content-Type is allowed for compression.
func (b *BlobStor) NeedsCompression(obj *object.Object) bool {
if !b.compressionEnabled || len(b.uncompressableContentTypes) == 0 {
return b.compressionEnabled
}