Update only specific props in registry update

Signed-off-by: cd1989 <chende@caicloud.io>
This commit is contained in:
cd1989 2019-04-09 14:00:30 +08:00
parent a1ec091955
commit 2ad8913e84
2 changed files with 3 additions and 13 deletions

View File

@ -1,8 +1,6 @@
package dao
import (
"time"
"github.com/astaxie/beego/orm"
"github.com/goharbor/harbor/src/common/dao"
@ -89,16 +87,10 @@ func ListRegistries(query ...*ListRegistryQuery) (int64, []*models.Registry, err
}
// UpdateRegistry updates one registry
func UpdateRegistry(registry *models.Registry) error {
func UpdateRegistry(registry *models.Registry, props ...string) error {
o := dao.GetOrmer()
sql := `update registry
set url = ?, name = ?, credential_type = ?, access_key = ?, access_secret = ?, type = ?, insecure = ?, health = ?, description = ?, update_time = ?
where id = ?`
_, err := o.Raw(sql, registry.URL, registry.Name, registry.CredentialType, registry.AccessKey, registry.AccessSecret,
registry.Type, registry.Insecure, registry.Health, registry.Description, time.Now(), registry.ID).Exec()
_, err := o.Update(registry, props...)
return err
}

View File

@ -136,8 +136,6 @@ func (m *DefaultManager) Add(registry *model.Registry) (int64, error) {
// Update updates a registry
func (m *DefaultManager) Update(registry *model.Registry, props ...string) error {
// TODO(ChenDe): Only update the given props
r, err := toDaoModel(registry)
if err != nil {
log.Errorf("Convert registry model to dao layer model error: %v", err)
@ -172,7 +170,7 @@ func (m *DefaultManager) HealthCheck() error {
log.Warningf("Check health status for %s error: %v", r.URL, err)
}
r.Status = string(status)
err = m.Update(r)
err = m.Update(r, "status")
if err != nil {
log.Warningf("Update health status for '%s' error: %v", r.URL, err)
errCount++