update code per review comments

Signed-off-by: wang yan <wangyan@vmware.com>
This commit is contained in:
wang yan 2019-08-29 10:58:18 +08:00
parent 942e793f20
commit 5decb56369
3 changed files with 15 additions and 12 deletions

View File

@ -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 ...

View File

@ -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) {

View File

@ -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)
}