diff --git a/models/etcd/asset_updater.go b/models/etcd/asset_updater.go index 90ec2fd0..3a51cec3 100644 --- a/models/etcd/asset_updater.go +++ b/models/etcd/asset_updater.go @@ -8,6 +8,7 @@ import ( "io" "math/rand" "net/http" + "slices" "strconv" "time" @@ -41,7 +42,13 @@ RETRY: return nil } + currentURLs := slices.Clone(a.URLs) a.URLs = append(a.URLs, d.myURL("/api/v1/assets", a.Name)) + slices.Sort(a.URLs) + slices.Compact(a.URLs) + if slices.Equal(currentURLs, a.URLs) || len(a.URLs) > maxAssetURLs { + return nil + } key := KeyAssets + a.Name j, err := json.Marshal(a) @@ -120,11 +127,9 @@ func (d *driver) downloadAsset(ctx context.Context, asset *sabakan.Asset) error return err } - if len(asset.URLs) < maxAssetURLs { - err = d.addAssetURL(ctx, asset) - if err != nil { - return err - } + err = d.addAssetURL(ctx, asset) + if err != nil { + return err } return nil