mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-22 08:38:03 +01:00
update code per review comments
Signed-off-by: wang yan <wangyan@vmware.com>
This commit is contained in:
parent
942e793f20
commit
5decb56369
@ -16,6 +16,7 @@ package dao
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/goharbor/harbor/src/common/models"
|
||||
@ -51,7 +52,14 @@ func AddBlobsToProject(projectID int64, blobs ...*models.Blob) (int64, error) {
|
||||
})
|
||||
}
|
||||
|
||||
return GetOrmer().InsertMulti(len(projectBlobs), projectBlobs)
|
||||
cnt, err := GetOrmer().InsertMulti(10, projectBlobs)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "duplicate key value violates unique constraint") {
|
||||
return cnt, ErrDupRows
|
||||
}
|
||||
return cnt, err
|
||||
}
|
||||
return cnt, nil
|
||||
}
|
||||
|
||||
// RemoveBlobsFromProject ...
|
||||
|
@ -50,7 +50,7 @@ func TestAddBlobsToProject(t *testing.T) {
|
||||
})
|
||||
require.Nil(t, err)
|
||||
|
||||
for i := 0; i < 8888; i++ {
|
||||
for i := 0; i < 88888; i++ {
|
||||
blob := &models.Blob{
|
||||
Digest: digest.FromString(utils.GenerateRandomString()).String(),
|
||||
Size: 100,
|
||||
@ -61,7 +61,7 @@ func TestAddBlobsToProject(t *testing.T) {
|
||||
}
|
||||
cnt, err := AddBlobsToProject(pid, blobs...)
|
||||
require.Nil(t, err)
|
||||
require.Equal(t, cnt, int64(8888))
|
||||
require.Equal(t, cnt, int64(88888))
|
||||
}
|
||||
|
||||
func TestHasBlobInProject(t *testing.T) {
|
||||
|
@ -280,15 +280,10 @@ func persistPB(projects []quota.ProjectInfo) error {
|
||||
log.Error(err)
|
||||
return err
|
||||
}
|
||||
for _, blobOfPro := range blobsOfPro {
|
||||
_, err = dao.AddBlobToProject(blobOfPro.ID, pro.ProjectID)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
if err == dao.ErrDupRows {
|
||||
continue
|
||||
}
|
||||
return err
|
||||
}
|
||||
_, err = dao.AddBlobsToProject(pro.ProjectID, blobsOfPro...)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return err
|
||||
}
|
||||
log.Infof("[Quota-Sync]:: success to persist project&blob for project: %s, progress... [%d/%d]", project.Name, i, total)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user