Skip to content

Commit

Permalink
fix dupulicate assets url (#275)
Browse files Browse the repository at this point in the history
Signed-off-by: YZ775 <yuzuki-mimura@cybozu.co.jp>
  • Loading branch information
YZ775 committed Jan 5, 2024
1 parent 1d898ce commit 3b1665d
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions models/etcd/asset_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"math/rand"
"net/http"
"slices"
"strconv"
"time"

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3b1665d

Please sign in to comment.