From 9e7185b65f7d0699e9be86a9699a81e95ad20985 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 1 Apr 2024 12:31:16 +0800 Subject: [PATCH 1/9] Add commit status summary table to reduce query from commit status table. After this change, commit status summary table will be used for final result, commit status table will be for details --- models/git/commit_status.go | 21 +++--- models/git/commit_status_summary.go | 74 +++++++++++++++++++ models/migrations/migrations.go | 4 + models/migrations/v1_23/v294.go | 18 +++++ services/actions/commit_status.go | 20 ++--- .../repository/commitstatus/commitstatus.go | 48 ++++++++++-- 6 files changed, 154 insertions(+), 31 deletions(-) create mode 100644 models/git/commit_status_summary.go create mode 100644 models/migrations/v1_23/v294.go diff --git a/models/git/commit_status.go b/models/git/commit_status.go index bb75dcca263b8..cf4d83889375f 100644 --- a/models/git/commit_status.go +++ b/models/git/commit_status.go @@ -292,30 +292,27 @@ func GetLatestCommitStatus(ctx context.Context, repoID int64, sha string, listOp } // GetLatestCommitStatusForPairs returns all statuses with a unique context for a given list of repo-sha pairs -func GetLatestCommitStatusForPairs(ctx context.Context, repoIDsToLatestCommitSHAs map[int64]string, listOptions db.ListOptions) (map[int64][]*CommitStatus, error) { +func GetLatestCommitStatusForPairs(ctx context.Context, repoShas []RepoSha) (map[int64][]*CommitStatus, error) { type result struct { Index int64 RepoID int64 + SHA string } - results := make([]result, 0, len(repoIDsToLatestCommitSHAs)) + results := make([]result, 0, len(repoShas)) getBase := func() *xorm.Session { return db.GetEngine(ctx).Table(&CommitStatus{}) } // Create a disjunction of conditions for each repoID and SHA pair - conds := make([]builder.Cond, 0, len(repoIDsToLatestCommitSHAs)) - for repoID, sha := range repoIDsToLatestCommitSHAs { - conds = append(conds, builder.Eq{"repo_id": repoID, "sha": sha}) + conds := make([]builder.Cond, 0, len(repoShas)) + for _, repoSha := range repoShas { + conds = append(conds, builder.Eq{"repo_id": repoSha.RepoID, "sha": repoSha.SHA}) } sess := getBase().Where(builder.Or(conds...)). - Select("max( `index` ) as `index`, repo_id"). - GroupBy("context_hash, repo_id").OrderBy("max( `index` ) desc") - - if !listOptions.IsListAll() { - sess = db.SetSessionPagination(sess, &listOptions) - } + Select("max( `index` ) as `index`, repo_id, sha"). + GroupBy("context_hash, repo_id, sha").OrderBy("max( `index` ) desc") err := sess.Find(&results) if err != nil { @@ -332,7 +329,7 @@ func GetLatestCommitStatusForPairs(ctx context.Context, repoIDsToLatestCommitSHA cond := builder.Eq{ "`index`": result.Index, "repo_id": result.RepoID, - "sha": repoIDsToLatestCommitSHAs[result.RepoID], + "sha": result.SHA, } conds = append(conds, cond) } diff --git a/models/git/commit_status_summary.go b/models/git/commit_status_summary.go new file mode 100644 index 0000000000000..ee7490c48eab2 --- /dev/null +++ b/models/git/commit_status_summary.go @@ -0,0 +1,74 @@ +// Copyright 2017 Gitea. All rights reserved. +// SPDX-License-Identifier: MIT + +package git + +import ( + "context" + + "code.gitea.io/gitea/models/db" + api "code.gitea.io/gitea/modules/structs" + "xorm.io/builder" +) + +// CommitStatusSummary holds the latest commit Status of a single Commit +type CommitStatusSummary struct { + ID int64 `xorm:"pk autoincr"` + RepoID int64 `xorm:"INDEX UNIQUE(repo_sha_index)"` + SHA string `xorm:"VARCHAR(64) NOT NULL INDEX UNIQUE(repo_sha_index)"` + State api.CommitStatusState `xorm:"VARCHAR(7) NOT NULL"` +} + +func init() { + db.RegisterModel(new(CommitStatusSummary)) +} + +type RepoSha struct { + RepoID int64 + SHA string +} + +func GetLatestCommitStatusForRepoAndSHAs(ctx context.Context, repoShas []RepoSha) ([]*CommitStatus, error) { + cond := builder.NewCond() + for _, rs := range repoShas { + cond = cond.Or(builder.Eq{"repo_id": rs.RepoID, "sha": rs.SHA}) + } + + var summaries []CommitStatusSummary + if err := db.GetEngine(ctx).Where(cond).Find(&summaries); err != nil { + return nil, err + } + + commitStatuses := make([]*CommitStatus, 0, len(repoShas)) + for _, summary := range summaries { + commitStatuses = append(commitStatuses, &CommitStatus{ + RepoID: summary.RepoID, + SHA: summary.SHA, + State: summary.State, + }) + } + return commitStatuses, nil +} + +func UpdateCommitStatusSummary(ctx context.Context, repoID int64, sha string) error { + commitStatuses, _, err := GetLatestCommitStatus(ctx, repoID, sha, db.ListOptionsAll) + if err != nil { + return err + } + state := CalcCommitStatus(commitStatuses) + if cnt, err := db.GetEngine(ctx).Where("repo_id=? AND sha=?", repoID, sha). + Cols("state"). + Update(&CommitStatusSummary{ + State: state.State, + }); err != nil { + return err + } else if cnt == 0 { + _, err = db.GetEngine(ctx).Insert(&CommitStatusSummary{ + RepoID: repoID, + SHA: sha, + State: state.State, + }) + return err + } + return nil +} diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 0daa799ff6754..16b6323631605 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -21,6 +21,7 @@ import ( "code.gitea.io/gitea/models/migrations/v1_20" "code.gitea.io/gitea/models/migrations/v1_21" "code.gitea.io/gitea/models/migrations/v1_22" + "code.gitea.io/gitea/models/migrations/v1_23" "code.gitea.io/gitea/models/migrations/v1_6" "code.gitea.io/gitea/models/migrations/v1_7" "code.gitea.io/gitea/models/migrations/v1_8" @@ -572,6 +573,9 @@ var migrations = []Migration{ NewMigration("Ensure every project has exactly one default column - No Op", noopMigration), // v293 -> v294 NewMigration("Ensure every project has exactly one default column", v1_22.CheckProjectColumnsConsistency), + + // Gitea 1.22.0 ends at 294 + NewMigration("Add commit status summary table", v1_23.AddCommitStatusSummary), } // GetCurrentDBVersion returns the current db version diff --git a/models/migrations/v1_23/v294.go b/models/migrations/v1_23/v294.go new file mode 100644 index 0000000000000..d0e174b5a4093 --- /dev/null +++ b/models/migrations/v1_23/v294.go @@ -0,0 +1,18 @@ +// Copyright 2024 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_23 //nolint + +import "xorm.io/xorm" + +func AddCommitStatusSummary(x *xorm.Engine) error { + type CommitStatusSummary struct { + ID int64 `xorm:"pk autoincr"` + RepoID int64 `xorm:"INDEX UNIQUE(repo_sha_index)"` + SHA string `xorm:"VARCHAR(64) NOT NULL INDEX UNIQUE(repo_sha_index)"` + State string `xorm:"VARCHAR(7) NOT NULL"` + } + // there is no migrations because if there is no data on this table, it will fall back to get data + // from commit status + return x.Sync2(new(CommitStatusSummary)) +} diff --git a/services/actions/commit_status.go b/services/actions/commit_status.go index 42365539271be..eb031511f6b95 100644 --- a/services/actions/commit_status.go +++ b/services/actions/commit_status.go @@ -16,6 +16,7 @@ import ( "code.gitea.io/gitea/modules/log" api "code.gitea.io/gitea/modules/structs" webhook_module "code.gitea.io/gitea/modules/webhook" + commitstatus_service "code.gitea.io/gitea/services/repository/commitstatus" "github.com/nektos/act/pkg/jobparser" ) @@ -122,18 +123,13 @@ func createCommitStatus(ctx context.Context, job *actions_model.ActionRunJob) er if err != nil { return fmt.Errorf("HashTypeInterfaceFromHashString: %w", err) } - if err := git_model.NewCommitStatus(ctx, git_model.NewCommitStatusOptions{ - Repo: repo, - SHA: commitID, - Creator: creator, - CommitStatus: &git_model.CommitStatus{ - SHA: sha, - TargetURL: fmt.Sprintf("%s/jobs/%d", run.Link(), index), - Description: description, - Context: ctxname, - CreatorID: creator.ID, - State: state, - }, + if err := commitstatus_service.CreateCommitStatus(ctx, repo, creator, commitID.String(), &git_model.CommitStatus{ + SHA: sha, + TargetURL: fmt.Sprintf("%s/jobs/%d", run.Link(), index), + Description: description, + Context: ctxname, + CreatorID: creator.ID, + State: state, }); err != nil { return fmt.Errorf("NewCommitStatus: %w", err) } diff --git a/services/repository/commitstatus/commitstatus.go b/services/repository/commitstatus/commitstatus.go index 145fc7d53c4e9..b1c751364fe10 100644 --- a/services/repository/commitstatus/commitstatus.go +++ b/services/repository/commitstatus/commitstatus.go @@ -7,6 +7,7 @@ import ( "context" "crypto/sha256" "fmt" + "slices" "code.gitea.io/gitea/models/db" git_model "code.gitea.io/gitea/models/git" @@ -59,13 +60,19 @@ func CreateCommitStatus(ctx context.Context, repo *repo_model.Repository, creato sha = commit.ID.String() } - if err := git_model.NewCommitStatus(ctx, git_model.NewCommitStatusOptions{ - Repo: repo, - Creator: creator, - SHA: commit.ID, - CommitStatus: status, + if err := db.WithTx(ctx, func(ctx context.Context) error { + if err := git_model.NewCommitStatus(ctx, git_model.NewCommitStatusOptions{ + Repo: repo, + Creator: creator, + SHA: commit.ID, + CommitStatus: status, + }); err != nil { + return fmt.Errorf("NewCommitStatus[repo_id: %d, user_id: %d, sha: %s]: %w", repo.ID, creator.ID, sha, err) + } + + return git_model.UpdateCommitStatusSummary(ctx, repo.ID, commit.ID.String()) }); err != nil { - return fmt.Errorf("NewCommitStatus[repo_id: %d, user_id: %d, sha: %s]: %w", repo.ID, creator.ID, sha, err) + return err } defaultBranchCommit, err := gitRepo.GetBranchCommit(repo.DefaultBranch) @@ -114,8 +121,35 @@ func FindReposLastestCommitStatuses(ctx context.Context, repos []*repo_model.Rep return nil, fmt.Errorf("FindBranchesByRepoAndBranchName: %v", err) } + var repoSha []git_model.RepoSha + for id, sha := range repoIDsToLatestCommitSHAs { + repoSha = append(repoSha, git_model.RepoSha{RepoID: id, SHA: sha}) + } + + summaryResults, err := git_model.GetLatestCommitStatusForRepoAndSHAs(ctx, repoSha) + if err != nil { + return nil, fmt.Errorf("GetLatestCommitStatusForRepoAndSHAs: %v", err) + } + + for _, summary := range summaryResults { + for i, repo := range repos { + if repo.ID == summary.RepoID { + results[i] = summary + _ = slices.DeleteFunc(repoSha, func(repoSha git_model.RepoSha) bool { + return repoSha.RepoID == repo.ID + }) + if results[i].State != "" { + if err := updateCommitStatusCache(ctx, repo.ID, repo.DefaultBranch, results[i].State); err != nil { + log.Error("updateCommitStatusCache[%d:%s] failed: %v", repo.ID, repo.DefaultBranch, err) + } + } + break + } + } + } + // call the database O(1) times to get the commit statuses for all repos - repoToItsLatestCommitStatuses, err := git_model.GetLatestCommitStatusForPairs(ctx, repoIDsToLatestCommitSHAs, db.ListOptionsAll) + repoToItsLatestCommitStatuses, err := git_model.GetLatestCommitStatusForPairs(ctx, repoSha) if err != nil { return nil, fmt.Errorf("GetLatestCommitStatusForPairs: %v", err) } From 6236384914b155495f1019c317894fa703d32c5c Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Tue, 2 Apr 2024 12:12:27 +0800 Subject: [PATCH 2/9] Correct some names --- models/git/commit_status.go | 10 +++++----- models/git/commit_status_summary.go | 11 ++++++----- services/repository/commitstatus/commitstatus.go | 10 +++++----- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/models/git/commit_status.go b/models/git/commit_status.go index cf4d83889375f..c3cda7b73d0e8 100644 --- a/models/git/commit_status.go +++ b/models/git/commit_status.go @@ -292,23 +292,23 @@ func GetLatestCommitStatus(ctx context.Context, repoID int64, sha string, listOp } // GetLatestCommitStatusForPairs returns all statuses with a unique context for a given list of repo-sha pairs -func GetLatestCommitStatusForPairs(ctx context.Context, repoShas []RepoSha) (map[int64][]*CommitStatus, error) { +func GetLatestCommitStatusForPairs(ctx context.Context, repoSHAs []RepoSHA) (map[int64][]*CommitStatus, error) { type result struct { Index int64 RepoID int64 SHA string } - results := make([]result, 0, len(repoShas)) + results := make([]result, 0, len(repoSHAs)) getBase := func() *xorm.Session { return db.GetEngine(ctx).Table(&CommitStatus{}) } // Create a disjunction of conditions for each repoID and SHA pair - conds := make([]builder.Cond, 0, len(repoShas)) - for _, repoSha := range repoShas { - conds = append(conds, builder.Eq{"repo_id": repoSha.RepoID, "sha": repoSha.SHA}) + conds := make([]builder.Cond, 0, len(repoSHAs)) + for _, repoSHA := range repoSHAs { + conds = append(conds, builder.Eq{"repo_id": repoSHA.RepoID, "sha": repoSHA.SHA}) } sess := getBase().Where(builder.Or(conds...)). Select("max( `index` ) as `index`, repo_id, sha"). diff --git a/models/git/commit_status_summary.go b/models/git/commit_status_summary.go index ee7490c48eab2..89fbe15f255db 100644 --- a/models/git/commit_status_summary.go +++ b/models/git/commit_status_summary.go @@ -1,4 +1,4 @@ -// Copyright 2017 Gitea. All rights reserved. +// Copyright 2024 Gitea. All rights reserved. // SPDX-License-Identifier: MIT package git @@ -8,6 +8,7 @@ import ( "code.gitea.io/gitea/models/db" api "code.gitea.io/gitea/modules/structs" + "xorm.io/builder" ) @@ -23,14 +24,14 @@ func init() { db.RegisterModel(new(CommitStatusSummary)) } -type RepoSha struct { +type RepoSHA struct { RepoID int64 SHA string } -func GetLatestCommitStatusForRepoAndSHAs(ctx context.Context, repoShas []RepoSha) ([]*CommitStatus, error) { +func GetLatestCommitStatusForRepoAndSHAs(ctx context.Context, repoSHAs []RepoSHA) ([]*CommitStatus, error) { cond := builder.NewCond() - for _, rs := range repoShas { + for _, rs := range repoSHAs { cond = cond.Or(builder.Eq{"repo_id": rs.RepoID, "sha": rs.SHA}) } @@ -39,7 +40,7 @@ func GetLatestCommitStatusForRepoAndSHAs(ctx context.Context, repoShas []RepoSha return nil, err } - commitStatuses := make([]*CommitStatus, 0, len(repoShas)) + commitStatuses := make([]*CommitStatus, 0, len(repoSHAs)) for _, summary := range summaries { commitStatuses = append(commitStatuses, &CommitStatus{ RepoID: summary.RepoID, diff --git a/services/repository/commitstatus/commitstatus.go b/services/repository/commitstatus/commitstatus.go index b1c751364fe10..88f8d4687232d 100644 --- a/services/repository/commitstatus/commitstatus.go +++ b/services/repository/commitstatus/commitstatus.go @@ -121,12 +121,12 @@ func FindReposLastestCommitStatuses(ctx context.Context, repos []*repo_model.Rep return nil, fmt.Errorf("FindBranchesByRepoAndBranchName: %v", err) } - var repoSha []git_model.RepoSha + var repoSHAs []git_model.RepoSHA for id, sha := range repoIDsToLatestCommitSHAs { - repoSha = append(repoSha, git_model.RepoSha{RepoID: id, SHA: sha}) + repoSHAs = append(repoSHAs, git_model.RepoSHA{RepoID: id, SHA: sha}) } - summaryResults, err := git_model.GetLatestCommitStatusForRepoAndSHAs(ctx, repoSha) + summaryResults, err := git_model.GetLatestCommitStatusForRepoAndSHAs(ctx, repoSHAs) if err != nil { return nil, fmt.Errorf("GetLatestCommitStatusForRepoAndSHAs: %v", err) } @@ -135,7 +135,7 @@ func FindReposLastestCommitStatuses(ctx context.Context, repos []*repo_model.Rep for i, repo := range repos { if repo.ID == summary.RepoID { results[i] = summary - _ = slices.DeleteFunc(repoSha, func(repoSha git_model.RepoSha) bool { + _ = slices.DeleteFunc(repoSHAs, func(repoSha git_model.RepoSHA) bool { return repoSha.RepoID == repo.ID }) if results[i].State != "" { @@ -149,7 +149,7 @@ func FindReposLastestCommitStatuses(ctx context.Context, repos []*repo_model.Rep } // call the database O(1) times to get the commit statuses for all repos - repoToItsLatestCommitStatuses, err := git_model.GetLatestCommitStatusForPairs(ctx, repoSha) + repoToItsLatestCommitStatuses, err := git_model.GetLatestCommitStatusForPairs(ctx, repoSHAs) if err != nil { return nil, fmt.Errorf("GetLatestCommitStatusForPairs: %v", err) } From 28d357e9a536d2419e4cde5b031f9cdb428bb329 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 7 Apr 2024 21:30:10 +0800 Subject: [PATCH 3/9] Fix upset for mysql --- models/git/commit_status_summary.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/models/git/commit_status_summary.go b/models/git/commit_status_summary.go index 89fbe15f255db..c3328f290b8af 100644 --- a/models/git/commit_status_summary.go +++ b/models/git/commit_status_summary.go @@ -7,6 +7,7 @@ import ( "context" "code.gitea.io/gitea/models/db" + "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" "xorm.io/builder" @@ -57,6 +58,12 @@ func UpdateCommitStatusSummary(ctx context.Context, repoID int64, sha string) er return err } state := CalcCommitStatus(commitStatuses) + if setting.Database.Type.IsMySQL() { + _, err := db.GetEngine(ctx).Exec("INSERT INTO commit_status_summary (repo_id,sha,state) VALUES (?,?,?) ON DUPLICATE KEY UPDATE state=?", + repoID, sha, state.State, state.State) + return err + } + if cnt, err := db.GetEngine(ctx).Where("repo_id=? AND sha=?", repoID, sha). Cols("state"). Update(&CommitStatusSummary{ From 8db71d05e845657619f44bdbd385ad22a60cea60 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 7 Apr 2024 21:33:15 +0800 Subject: [PATCH 4/9] Add a comment for upset --- models/git/commit_status_summary.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/models/git/commit_status_summary.go b/models/git/commit_status_summary.go index c3328f290b8af..fd6a022babbce 100644 --- a/models/git/commit_status_summary.go +++ b/models/git/commit_status_summary.go @@ -58,6 +58,8 @@ func UpdateCommitStatusSummary(ctx context.Context, repoID int64, sha string) er return err } state := CalcCommitStatus(commitStatuses) + // mysql will return 0 when update a record which state hasn't been changed which behaviour is different from other database, + // so we need to use insert in on duplicate if setting.Database.Type.IsMySQL() { _, err := db.GetEngine(ctx).Exec("INSERT INTO commit_status_summary (repo_id,sha,state) VALUES (?,?,?) ON DUPLICATE KEY UPDATE state=?", repoID, sha, state.State, state.State) From 1beb1826b1290efd53d724399599fcb72cf1bf3a Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 7 Apr 2024 22:32:47 +0800 Subject: [PATCH 5/9] Add test for commit status summary --- tests/integration/pull_status_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/integration/pull_status_test.go b/tests/integration/pull_status_test.go index 26c99e6445974..bb7098e42425e 100644 --- a/tests/integration/pull_status_test.go +++ b/tests/integration/pull_status_test.go @@ -12,6 +12,9 @@ import ( "testing" auth_model "code.gitea.io/gitea/models/auth" + git_model "code.gitea.io/gitea/models/git" + repo_model "code.gitea.io/gitea/models/repo" + "code.gitea.io/gitea/models/unittest" api "code.gitea.io/gitea/modules/structs" "github.com/stretchr/testify/assert" @@ -90,6 +93,10 @@ func TestPullCreate_CommitStatus(t *testing.T) { assert.True(t, ok) assert.Contains(t, cls, statesIcons[status]) } + + repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerName: "user1", Name: "repo1"}) + css := unittest.AssertExistsAndLoadBean(t, &git_model.CommitStatusSummary{RepoID: repo1.ID, SHA: commitID}) + assert.EqualValues(t, api.CommitStatusWarning, css.State) }) } From a6538096deb8d9f41ba370349c39be701854944c Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 8 Apr 2024 17:29:27 +0800 Subject: [PATCH 6/9] Apply suggestions from code review Co-authored-by: Jason Song --- models/git/commit_status_summary.go | 4 ++-- models/migrations/v1_23/v295.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/models/git/commit_status_summary.go b/models/git/commit_status_summary.go index fd6a022babbce..9c6f834f44473 100644 --- a/models/git/commit_status_summary.go +++ b/models/git/commit_status_summary.go @@ -16,8 +16,8 @@ import ( // CommitStatusSummary holds the latest commit Status of a single Commit type CommitStatusSummary struct { ID int64 `xorm:"pk autoincr"` - RepoID int64 `xorm:"INDEX UNIQUE(repo_sha_index)"` - SHA string `xorm:"VARCHAR(64) NOT NULL INDEX UNIQUE(repo_sha_index)"` + RepoID int64 `xorm:"INDEX UNIQUE(repo_sha)"` + SHA string `xorm:"VARCHAR(64) NOT NULL INDEX UNIQUE(repo_sha)"` State api.CommitStatusState `xorm:"VARCHAR(7) NOT NULL"` } diff --git a/models/migrations/v1_23/v295.go b/models/migrations/v1_23/v295.go index d0e174b5a4093..c9246da3f0932 100644 --- a/models/migrations/v1_23/v295.go +++ b/models/migrations/v1_23/v295.go @@ -8,8 +8,8 @@ import "xorm.io/xorm" func AddCommitStatusSummary(x *xorm.Engine) error { type CommitStatusSummary struct { ID int64 `xorm:"pk autoincr"` - RepoID int64 `xorm:"INDEX UNIQUE(repo_sha_index)"` - SHA string `xorm:"VARCHAR(64) NOT NULL INDEX UNIQUE(repo_sha_index)"` + RepoID int64 `xorm:"INDEX UNIQUE(repo_sha)"` + SHA string `xorm:"VARCHAR(64) NOT NULL INDEX UNIQUE(repo_sha)"` State string `xorm:"VARCHAR(7) NOT NULL"` } // there is no migrations because if there is no data on this table, it will fall back to get data From 32b679041cee276ce52cd952dae76bd026b94c4c Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 10 Apr 2024 13:32:38 +0800 Subject: [PATCH 7/9] Rename index name on commist_status_summary table --- models/git/commit_status_summary.go | 4 ++-- models/migrations/v1_23/v295.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/models/git/commit_status_summary.go b/models/git/commit_status_summary.go index fd6a022babbce..01674e943d04f 100644 --- a/models/git/commit_status_summary.go +++ b/models/git/commit_status_summary.go @@ -16,8 +16,8 @@ import ( // CommitStatusSummary holds the latest commit Status of a single Commit type CommitStatusSummary struct { ID int64 `xorm:"pk autoincr"` - RepoID int64 `xorm:"INDEX UNIQUE(repo_sha_index)"` - SHA string `xorm:"VARCHAR(64) NOT NULL INDEX UNIQUE(repo_sha_index)"` + RepoID int64 `xorm:"INDEX UNIQUE(repo_id_sha)"` + SHA string `xorm:"VARCHAR(64) NOT NULL INDEX UNIQUE(repo_id_sha)"` State api.CommitStatusState `xorm:"VARCHAR(7) NOT NULL"` } diff --git a/models/migrations/v1_23/v295.go b/models/migrations/v1_23/v295.go index d0e174b5a4093..9a2003cfc1165 100644 --- a/models/migrations/v1_23/v295.go +++ b/models/migrations/v1_23/v295.go @@ -8,8 +8,8 @@ import "xorm.io/xorm" func AddCommitStatusSummary(x *xorm.Engine) error { type CommitStatusSummary struct { ID int64 `xorm:"pk autoincr"` - RepoID int64 `xorm:"INDEX UNIQUE(repo_sha_index)"` - SHA string `xorm:"VARCHAR(64) NOT NULL INDEX UNIQUE(repo_sha_index)"` + RepoID int64 `xorm:"INDEX UNIQUE(repo_id_sha)"` + SHA string `xorm:"VARCHAR(64) NOT NULL INDEX UNIQUE(repo_id_sha)"` State string `xorm:"VARCHAR(7) NOT NULL"` } // there is no migrations because if there is no data on this table, it will fall back to get data From 027ae023497fada797cff9b27354e097535712d9 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 10 Apr 2024 13:58:54 +0800 Subject: [PATCH 8/9] Fix variable name --- services/repository/commitstatus/commitstatus.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/repository/commitstatus/commitstatus.go b/services/repository/commitstatus/commitstatus.go index 88f8d4687232d..167a5330ddc49 100644 --- a/services/repository/commitstatus/commitstatus.go +++ b/services/repository/commitstatus/commitstatus.go @@ -135,8 +135,8 @@ func FindReposLastestCommitStatuses(ctx context.Context, repos []*repo_model.Rep for i, repo := range repos { if repo.ID == summary.RepoID { results[i] = summary - _ = slices.DeleteFunc(repoSHAs, func(repoSha git_model.RepoSHA) bool { - return repoSha.RepoID == repo.ID + _ = slices.DeleteFunc(repoSHAs, func(repoSHA git_model.RepoSHA) bool { + return repoSHA.RepoID == repo.ID }) if results[i].State != "" { if err := updateCommitStatusCache(ctx, repo.ID, repo.DefaultBranch, results[i].State); err != nil { From d46bdd1c7df23482095254efd7b2dd3feb0f848c Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 10 Apr 2024 15:03:36 +0800 Subject: [PATCH 9/9] revert unnecessary removed blank line --- models/migrations/migrations.go | 1 + 1 file changed, 1 insertion(+) diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index 9d5cac27493b6..3ea8f2acbf260 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -575,6 +575,7 @@ var migrations = []Migration{ NewMigration("Ensure every project has exactly one default column", v1_22.CheckProjectColumnsConsistency), // Gitea 1.22.0 ends at 294 + // v294 -> v295 NewMigration("Add unique index for project issue table", v1_23.AddUniqueIndexForProjectIssue), // v295 -> v296