mirror of https://github.com/cloudreve/Cloudreve
feat(storage): load balance storage policy (#2436)
parent
a0aefef691
commit
aada3aab02
2
assets
2
assets
|
@ -1 +1 @@
|
|||
Subproject commit 8e2c2bcff17d4728a01c2cabab8c3b639d72f428
|
||||
Subproject commit 27996dc3ea22ab3b7ae525841ad1d45098d375f4
|
|
@ -27,6 +27,7 @@ type (
|
|||
SkipStoragePolicyCache struct{}
|
||||
|
||||
StoragePolicyClient interface {
|
||||
TxOperator
|
||||
// GetByGroup returns the storage policies of the group.
|
||||
GetByGroup(ctx context.Context, group *ent.Group) (*ent.StoragePolicy, error)
|
||||
// GetPolicyByID returns the storage policy by id.
|
||||
|
@ -64,6 +65,14 @@ type storagePolicyClient struct {
|
|||
cache cache.Driver
|
||||
}
|
||||
|
||||
func (c *storagePolicyClient) SetClient(newClient *ent.Client) TxOperator {
|
||||
return &storagePolicyClient{client: newClient, cache: c.cache}
|
||||
}
|
||||
|
||||
func (c *storagePolicyClient) GetClient() *ent.Client {
|
||||
return c.client
|
||||
}
|
||||
|
||||
func (c *storagePolicyClient) Delete(ctx context.Context, policy *ent.StoragePolicy) error {
|
||||
if err := c.client.StoragePolicy.DeleteOne(policy).Exec(ctx); err != nil {
|
||||
return fmt.Errorf("failed to delete storage policy: %w", err)
|
||||
|
|
|
@ -294,11 +294,22 @@ func (service *UpdateStoragePolicyService) Update(c *gin.Context) (*GetStoragePo
|
|||
}
|
||||
|
||||
service.Policy.ID = idInt
|
||||
_, err = storagePolicyClient.Upsert(c, service.Policy)
|
||||
|
||||
sc, tx, ctx, err := inventory.WithTx(c, storagePolicyClient)
|
||||
if err != nil {
|
||||
return nil, serializer.NewError(serializer.CodeDBError, "Failed to create transaction", err)
|
||||
}
|
||||
|
||||
_, err = sc.Upsert(ctx, service.Policy)
|
||||
if err != nil {
|
||||
_ = inventory.Rollback(tx)
|
||||
return nil, serializer.NewError(serializer.CodeDBError, "Failed to update policy", err)
|
||||
}
|
||||
|
||||
if err := inventory.Commit(tx); err != nil {
|
||||
return nil, serializer.NewError(serializer.CodeDBError, "Failed to commit transaction", err)
|
||||
}
|
||||
|
||||
_ = dep.KV().Delete(manager.EntityUrlCacheKeyPrefix)
|
||||
|
||||
s := SingleStoragePolicyService{ID: idInt}
|
||||
|
|
Loading…
Reference in New Issue