cache invalidation for mutations
This commit is contained in:
parent
818264093f
commit
ad80860368
@ -3,7 +3,9 @@ package s3browser
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/graph-gophers/dataloader"
|
||||||
"github.com/minio/minio-go/v7"
|
"github.com/minio/minio-go/v7"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -16,7 +18,23 @@ func deleteMutation(ctx context.Context, id string) error {
|
|||||||
|
|
||||||
// TODO: it is posible to remove multiple objects with a single call.
|
// TODO: it is posible to remove multiple objects with a single call.
|
||||||
// Is it better to batch this?
|
// Is it better to batch this?
|
||||||
return s3Client.RemoveObject(ctx, bucketName, id, minio.RemoveObjectOptions{})
|
err := s3Client.RemoveObject(ctx, bucketName, id, minio.RemoveObjectOptions{})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Invalidate cache
|
||||||
|
loader, ok := ctx.Value("loader").(map[string]*dataloader.Loader)
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Failed to get loader from context")
|
||||||
|
}
|
||||||
|
|
||||||
|
loader["getFile"].Clear(ctx, dataloader.StringKey(id))
|
||||||
|
loader["listObjects"].Clear(ctx, dataloader.StringKey(id))
|
||||||
|
loader["getFiles"].Clear(ctx, dataloader.StringKey(filepath.Dir(id)))
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func copyMutation(ctx context.Context, src, dest string) (*File, error) {
|
func copyMutation(ctx context.Context, src, dest string) (*File, error) {
|
||||||
@ -38,6 +56,18 @@ func copyMutation(ctx context.Context, src, dest string) (*File, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Invalidate cache
|
||||||
|
|
||||||
|
loader, ok := ctx.Value("loader").(map[string]*dataloader.Loader)
|
||||||
|
|
||||||
|
// TODO: Do we want to error when the operation
|
||||||
|
// has succeeded but the cache invalidation has failed ?
|
||||||
|
if ok {
|
||||||
|
loader["getFile"].Clear(ctx, dataloader.StringKey(info.Key))
|
||||||
|
loader["listObjects"].Clear(ctx, dataloader.StringKey(info.Key))
|
||||||
|
loader["getFiles"].Clear(ctx, dataloader.StringKey(filepath.Dir(info.Key)))
|
||||||
|
}
|
||||||
|
|
||||||
return &File{
|
return &File{
|
||||||
ID: info.Key,
|
ID: info.Key,
|
||||||
}, nil
|
}, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user