From e8722c06e910b89ac10be84c518e5040ac5ddc4f Mon Sep 17 00:00:00 2001 From: Wang Yan Date: Thu, 24 Oct 2024 14:13:58 +0800 Subject: [PATCH] add pagesize for replicaiton (#21081) fixes #20430, set the pagesize to 100 when to list artifact on replication Signed-off-by: wang yan --- src/pkg/reg/adapter/harbor/v2/adapter.go | 2 +- src/pkg/reg/adapter/harbor/v2/client.go | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/pkg/reg/adapter/harbor/v2/adapter.go b/src/pkg/reg/adapter/harbor/v2/adapter.go index bf322295a..eef19bbae 100644 --- a/src/pkg/reg/adapter/harbor/v2/adapter.go +++ b/src/pkg/reg/adapter/harbor/v2/adapter.go @@ -32,7 +32,7 @@ var _ adp.ArtifactRegistry = &adapter{} func New(base *base.Adapter) adp.Adapter { return &adapter{ Adapter: base, - client: &client{Client: base.Client}, + client: &client{Client: base.Client, pageSize: 100}, } } diff --git a/src/pkg/reg/adapter/harbor/v2/client.go b/src/pkg/reg/adapter/harbor/v2/client.go index fa6808466..88b776a8a 100644 --- a/src/pkg/reg/adapter/harbor/v2/client.go +++ b/src/pkg/reg/adapter/harbor/v2/client.go @@ -30,6 +30,7 @@ import ( type client struct { *base.Client + pageSize int64 } func (c *client) listRepositories(project *base.Project) ([]*model.Repository, error) { @@ -51,8 +52,12 @@ func (c *client) listRepositories(project *base.Project) ([]*model.Repository, e func (c *client) listArtifacts(repo string) ([]*model.Artifact, error) { project, repo := utils.ParseRepository(repo) repo = repository.Encode(repo) - url := fmt.Sprintf("%s/projects/%s/repositories/%s/artifacts?with_label=true&with_accessory=true", - c.BasePath(), project, repo) + // set the default value to equal the value specified when the UI submits the request + if c.pageSize == 0 { + c.pageSize = 15 + } + url := fmt.Sprintf("%s/projects/%s/repositories/%s/artifacts?page_size=%d&with_label=true&with_accessory=true", + c.BasePath(), project, repo, c.pageSize) artifacts := []*artifact.Artifact{} if err := c.C.GetAndIteratePagination(url, &artifacts); err != nil { return nil, err