From 4891f104f06f2d92cc3c9c52e11f22bd8bd2b8ba Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 15 Nov 2021 00:55:37 +0100 Subject: [PATCH] Update only relevant cols on repo sync (#512) close #511 --- server/store/datastore/repo.go | 9 ++++++++- server/store/datastore/repo_test.go | 26 ++++++++++++++++++++------ 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/server/store/datastore/repo.go b/server/store/datastore/repo.go index 08260d2db..1aa8024fb 100644 --- a/server/store/datastore/repo.go +++ b/server/store/datastore/repo.go @@ -95,10 +95,17 @@ func (s storage) RepoBatch(repos []*model.Repo) error { if exist { if _, err := sess. Where("repo_owner = ? AND repo_name = ?", repos[i].Owner, repos[i].Name). - AllCols(). + Cols("repo_scm", "repo_avatar", "repo_link", "repo_private", "repo_clone", "repo_branch"). Update(repos[i]); err != nil { return err } + + _, err := sess. + Where("repo_owner = ? AND repo_name = ?", repos[i].Owner, repos[i].Name). + Get(repos[i]) + if err != nil { + return err + } } else { // only Insert on single object ref set auto created ID back to object if _, err := sess.Insert(repos[i]); err != nil { diff --git a/server/store/datastore/repo_test.go b/server/store/datastore/repo_test.go index 9237a7fa3..78e43b174 100644 --- a/server/store/datastore/repo_test.go +++ b/server/store/datastore/repo_test.go @@ -153,10 +153,12 @@ func TestRepoList(t *testing.T) { assert.NoError(t, store.CreateRepo(repo2)) assert.NoError(t, store.CreateRepo(repo3)) - assert.NoError(t, store.PermBatch([]*model.Perm{ + for _, perm := range []*model.Perm{ {UserID: user.ID, Repo: repo1.FullName}, {UserID: user.ID, Repo: repo2.FullName}, - })) + } { + assert.NoError(t, store.PermUpsert(perm)) + } repos, err := store.RepoList(user, false) if err != nil { @@ -210,12 +212,14 @@ func TestOwnedRepoList(t *testing.T) { assert.NoError(t, store.CreateRepo(repo3)) assert.NoError(t, store.CreateRepo(repo4)) - assert.NoError(t, store.PermBatch([]*model.Perm{ + for _, perm := range []*model.Perm{ {UserID: user.ID, Repo: repo1.FullName, Push: true, Admin: false}, {UserID: user.ID, Repo: repo2.FullName, Push: false, Admin: true}, {UserID: user.ID, Repo: repo3.FullName}, {UserID: user.ID, Repo: repo4.FullName}, - })) + } { + assert.NoError(t, store.PermUpsert(perm)) + } repos, err := store.RepoList(user, true) if err != nil { @@ -313,9 +317,19 @@ func TestRepoBatch(t *testing.T) { return } - allRepos := make([]*model.Repo, 0, 4) - err := store.engine.Find(&allRepos) + repo := &model.Repo{ + FullName: "foo/bar", + Owner: "foo", + Name: "bar", + } + assert.NoError(t, store.RepoBatch([]*model.Repo{repo})) + assert.EqualValues(t, repos[0].ID, repo.ID) + _, err := store.engine.ID(repo.ID).Get(repo) assert.NoError(t, err) + assert.True(t, repo.IsActive) + + allRepos := make([]*model.Repo, 0, 4) + assert.NoError(t, store.engine.Find(&allRepos)) assert.Len(t, allRepos, 4) count, err := store.GetRepoCount()