From 2ad8913e846084db7fa46bc60a8b5db63792846d Mon Sep 17 00:00:00 2001 From: cd1989 Date: Tue, 9 Apr 2019 14:00:30 +0800 Subject: [PATCH] Update only specific props in registry update Signed-off-by: cd1989 --- src/replication/ng/dao/registry.go | 12 ++---------- src/replication/ng/registry/manager.go | 4 +--- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/replication/ng/dao/registry.go b/src/replication/ng/dao/registry.go index 75ea690e0..3dc7f5dd5 100644 --- a/src/replication/ng/dao/registry.go +++ b/src/replication/ng/dao/registry.go @@ -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 } diff --git a/src/replication/ng/registry/manager.go b/src/replication/ng/registry/manager.go index 6382d674e..42f5f06a3 100644 --- a/src/replication/ng/registry/manager.go +++ b/src/replication/ng/registry/manager.go @@ -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++