summaryrefslogtreecommitdiff
path: root/vendor/codeberg.org/gruf/go-storage/s3/errors.go
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 /vendor/codeberg.org/gruf/go-storage/s3/errors.go
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 'vendor/codeberg.org/gruf/go-storage/s3/errors.go')
-rw-r--r--vendor/codeberg.org/gruf/go-storage/s3/errors.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/vendor/codeberg.org/gruf/go-storage/s3/errors.go b/vendor/codeberg.org/gruf/go-storage/s3/errors.go
index 1f4404469..0b2d3be62 100644
--- a/vendor/codeberg.org/gruf/go-storage/s3/errors.go
+++ b/vendor/codeberg.org/gruf/go-storage/s3/errors.go
@@ -3,9 +3,35 @@ package s3
import (
"strings"
+ "codeberg.org/gruf/go-storage"
+ "codeberg.org/gruf/go-storage/internal"
"github.com/minio/minio-go/v7"
)
+// CachedErrorResponse can be returned
+// when an S3 is configured with caching,
+// and the basic details of an error
+// response have been stored in the cache.
+type CachedErrorResponse struct {
+ Code string
+ Key string
+}
+
+func (err *CachedErrorResponse) Error() string {
+ return "cached '" + err.Code + "' response for key:" + err.Key
+}
+
+func (err *CachedErrorResponse) Is(other error) bool {
+ switch other {
+ case storage.ErrNotFound:
+ return err.Code == "NoSuchKey"
+ case storage.ErrAlreadyExists:
+ return err.Code == "Conflict"
+ default:
+ return false
+ }
+}
+
func isNotFoundError(err error) bool {
errRsp, ok := err.(minio.ErrorResponse)
return ok && errRsp.Code == "NoSuchKey"
@@ -19,3 +45,8 @@ func isConflictError(err error) bool {
func isObjectNameError(err error) bool {
return strings.HasPrefix(err.Error(), "Object name ")
}
+
+func cachedNotFoundError(key string) error {
+ err := CachedErrorResponse{Code: "NoSuchKey", Key: key}
+ return internal.WrapErr(&err, storage.ErrNotFound)
+}