summaryrefslogtreecommitdiff
path: root/internal/storage
diff options
context:
space:
mode:
authorLibravatar kim <grufwub@gmail.com>2025-11-10 12:36:59 +0100
committerLibravatar tobi <tobi.smethurst@protonmail.com>2025-11-17 14:13:24 +0100
commitac877bde815827f7aa1eeb3a6f0513d4c7503ad0 (patch)
tree7a315d820a5be3232dd5bfc96857017c38e906fd /internal/storage
parent[chore] update dependencies (#4542) (diff)
downloadgotosocial-ac877bde815827f7aa1eeb3a6f0513d4c7503ad0.tar.xz
[performance] add optional S3 object info caching (#4546)
This adds an optional S3 object info cache to the S3 storage driver backend (see [here](https://codeberg.org/gruf/go-storage/releases/tag/v0.4.0)) to reduce S3 calls largely during media cleanup operations, but it should also help in other situations cutting back on S3 calls when for example a key is already known to not exist. Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4546 Co-authored-by: kim <grufwub@gmail.com> Co-committed-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/storage')
-rw-r--r--internal/storage/storage.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/internal/storage/storage.go b/internal/storage/storage.go
index 2c47017b3..c513edafd 100644
--- a/internal/storage/storage.go
+++ b/internal/storage/storage.go
@@ -34,6 +34,7 @@ import (
"codeberg.org/gruf/go-cache/v3/ttl"
"codeberg.org/gruf/go-storage"
"codeberg.org/gruf/go-storage/s3"
+ s3cache "codeberg.org/gruf/go-storage/s3/cache"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
)
@@ -240,7 +241,14 @@ func NewS3Storage() (*Driver, error) {
bucketLookup = minio.BucketLookupAuto
}
- // Open the s3 storage implementation
+ var objCache s3.EntryCache
+
+ // Check if an S3 object info cache was requested.
+ if cap := config.GetCacheS3ObjectInfo(); cap > 0 {
+ objCache = s3cache.New(0, cap)
+ }
+
+ // Open the s3 storage backend with configuration.
s3, err := s3.Open(endpoint, bucket, &s3.Config{
KeyPrefix: config.GetStorageS3KeyPrefix(),
CoreOpts: minio.Options{
@@ -250,6 +258,7 @@ func NewS3Storage() (*Driver, error) {
},
PutChunkSize: 5 * 1024 * 1024, // 5MiB
ListSize: 200,
+ Cache: objCache,
})
if err != nil {
return nil, fmt.Errorf("error opening s3 storage: %w", err)