From 51fbccdc48d0a2fb08869b6c85a9cd6bcd9a95f6 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 27 Dec 2020 19:07:47 +0000 Subject: [PATCH 1/5] remove CommitStatus.Index field, and update db index to use ID instead of Index. --- models/commit_status.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/models/commit_status.go b/models/commit_status.go index 5d637afc2b580..ce9f34a4ab660 100644 --- a/models/commit_status.go +++ b/models/commit_status.go @@ -21,12 +21,11 @@ import ( // CommitStatus holds a single Status of a single Commit type CommitStatus struct { - ID int64 `xorm:"pk autoincr"` - Index int64 `xorm:"INDEX UNIQUE(repo_sha_index)"` - RepoID int64 `xorm:"INDEX UNIQUE(repo_sha_index)"` + ID int64 `xorm:"pk autoincr INDEX UNIQUE(repo_sha_id)"` + RepoID int64 `xorm:"INDEX UNIQUE(repo_sha_id)"` Repo *Repository `xorm:"-"` State api.CommitStatusState `xorm:"VARCHAR(7) NOT NULL"` - SHA string `xorm:"VARCHAR(64) NOT NULL INDEX UNIQUE(repo_sha_index)"` + SHA string `xorm:"VARCHAR(64) NOT NULL INDEX UNIQUE(repo_sha_id)"` TargetURL string `xorm:"TEXT"` Description string `xorm:"TEXT"` ContextHash string `xorm:"char(40) index"` From 2e1d9cdd0c42b6a9d8ecc1b77dfb5954a828c2c0 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 27 Dec 2020 19:08:47 +0000 Subject: [PATCH 2/5] remove the fetching and incrementing of the index field --- models/commit_status.go | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/models/commit_status.go b/models/commit_status.go index ce9f34a4ab660..a13f07657d472 100644 --- a/models/commit_status.go +++ b/models/commit_status.go @@ -216,30 +216,12 @@ func NewCommitStatus(opts NewCommitStatusOptions) error { opts.CommitStatus.CreatorID = opts.Creator.ID opts.CommitStatus.RepoID = opts.Repo.ID - // Get the next Status Index - var nextIndex int64 - lastCommitStatus := &CommitStatus{ - SHA: opts.SHA, - RepoID: opts.Repo.ID, - } - has, err := sess.Desc("index").Limit(1).Get(lastCommitStatus) - if err != nil { - if err := sess.Rollback(); err != nil { - log.Error("NewCommitStatus: sess.Rollback: %v", err) - } - return fmt.Errorf("NewCommitStatus[%s, %s]: %v", repoPath, opts.SHA, err) - } - if has { - log.Debug("NewCommitStatus[%s, %s]: found", repoPath, opts.SHA) - nextIndex = lastCommitStatus.Index - } - opts.CommitStatus.Index = nextIndex + 1 - log.Debug("NewCommitStatus[%s, %s]: %d", repoPath, opts.SHA, opts.CommitStatus.Index) + log.Debug("NewCommitStatus[%s, %s]", repoPath, opts.SHA) opts.CommitStatus.ContextHash = hashCommitStatusContext(opts.CommitStatus.Context) // Insert new CommitStatus - if _, err = sess.Insert(opts.CommitStatus); err != nil { + if _, err := sess.Insert(opts.CommitStatus); err != nil { if err := sess.Rollback(); err != nil { log.Error("Insert CommitStatus: sess.Rollback: %v", err) } From edea3e1fac3cc9782fe885fd1ddaa66c66d8d349 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 27 Dec 2020 19:09:15 +0000 Subject: [PATCH 3/5] make the order by use ID instead of Index --- models/commit_status.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/models/commit_status.go b/models/commit_status.go index a13f07657d472..bdde476a4def1 100644 --- a/models/commit_status.go +++ b/models/commit_status.go @@ -129,9 +129,9 @@ func sortCommitStatusesSession(sess *xorm.Session, sortType string) { case "leastupdate": sess.Asc("updated_unix") case "leastindex": - sess.Desc("index") + sess.Desc("id") case "highestindex": - sess.Asc("index") + sess.Asc("id") default: sess.Desc("created_unix") } From 44c0d9892a96940109a42ec386074f0b6f18234f Mon Sep 17 00:00:00 2001 From: James Date: Sun, 27 Dec 2020 19:09:29 +0000 Subject: [PATCH 4/5] make the API ID use ID instead of Index --- modules/convert/status.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/convert/status.go b/modules/convert/status.go index f972fc333c133..1f0fe457694ec 100644 --- a/modules/convert/status.go +++ b/modules/convert/status.go @@ -17,7 +17,7 @@ func ToCommitStatus(status *models.CommitStatus) *api.CommitStatus { State: status.State, TargetURL: status.TargetURL, Description: status.Description, - ID: status.Index, + ID: status.ID, URL: status.APIURL(), Context: status.Context, } From 96023c2138140a765d83685082bec2c1f7fe9a23 Mon Sep 17 00:00:00 2001 From: James Date: Sun, 27 Dec 2020 19:45:47 +0000 Subject: [PATCH 5/5] remove commit_status.index from fixtures --- models/fixtures/commit_status.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/models/fixtures/commit_status.yml b/models/fixtures/commit_status.yml index 20d57975ef40d..6161b7c7bd105 100644 --- a/models/fixtures/commit_status.yml +++ b/models/fixtures/commit_status.yml @@ -1,6 +1,5 @@ - id: 1 - index: 1 repo_id: 1 state: "pending" sha: "1234123412341234123412341234123412341234" @@ -11,7 +10,6 @@ - id: 2 - index: 2 repo_id: 1 state: "warning" sha: "1234123412341234123412341234123412341234" @@ -22,7 +20,6 @@ - id: 3 - index: 3 repo_id: 1 state: "success" sha: "1234123412341234123412341234123412341234" @@ -33,7 +30,6 @@ - id: 4 - index: 4 repo_id: 1 state: "failure" sha: "1234123412341234123412341234123412341234" @@ -44,7 +40,6 @@ - id: 5 - index: 5 repo_id: 1 state: "error" sha: "1234123412341234123412341234123412341234"