Skip to content

Only git operations should update the updated_unix column in repository table #34388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions models/actions/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ func (run *ActionRun) IsSchedule() bool {

func updateRepoRunsNumbers(ctx context.Context, repo *repo_model.Repository) error {
_, err := db.GetEngine(ctx).ID(repo.ID).
NoAutoTime().
SetExpr("num_action_runs",
builder.Select("count(*)").From("action_run").
Where(builder.Eq{"repo_id": repo.ID}),
Expand Down
2 changes: 1 addition & 1 deletion models/repo/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func CreatePendingRepositoryTransfer(ctx context.Context, doer, newOwner *user_m
}

repo.Status = RepositoryPendingTransfer
if err := UpdateRepositoryCols(ctx, repo, "status"); err != nil {
if err := UpdateRepositoryColsNoAutoTime(ctx, repo, "status"); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion models/repo/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func UpdateRepositoryOwnerNames(ctx context.Context, ownerID int64, ownerName st
}
defer committer.Close()

if _, err := db.GetEngine(ctx).Where("owner_id = ?", ownerID).Cols("owner_name").Update(&Repository{
if _, err := db.GetEngine(ctx).Where("owner_id = ?", ownerID).Cols("owner_name").NoAutoTime().Update(&Repository{
OwnerName: ownerName,
}); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion routers/private/hook_post_receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) {
}

if len(cols) > 0 {
if err := repo_model.UpdateRepositoryCols(ctx, repo, cols...); err != nil {
if err := repo_model.UpdateRepositoryColsNoAutoTime(ctx, repo, cols...); err != nil {
log.Error("Failed to Update: %s/%s Error: %v", ownerName, repoName, err)
ctx.JSON(http.StatusInternalServerError, private.HookPostReceiveResult{
Err: fmt.Sprintf("Failed to Update: %s/%s Error: %v", ownerName, repoName, err),
Expand Down
6 changes: 0 additions & 6 deletions routers/web/repo/editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,12 +376,6 @@ func editFilePost(ctx *context.Context, form forms.EditRepoFileForm, isNewFile b
}
}

if ctx.Repo.Repository.IsEmpty {
if isEmpty, err := ctx.Repo.GitRepo.IsEmpty(); err == nil && !isEmpty {
_ = repo_model.UpdateRepositoryCols(ctx, &repo_model.Repository{ID: ctx.Repo.Repository.ID, IsEmpty: false}, "is_empty")
}
}

redirectForCommitChoice(ctx, form.CommitChoice, branchName, form.TreePath)
}

Expand Down
2 changes: 1 addition & 1 deletion routers/web/repo/wiki.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func findWikiRepoCommit(ctx *context.Context) (*git.Repository, *git.Commit, err
return wikiGitRepo, nil, errBranch
}
// update the default branch in the database
errDb := repo_model.UpdateRepositoryCols(ctx, &repo_model.Repository{ID: ctx.Repo.Repository.ID, DefaultWikiBranch: gitRepoDefaultBranch}, "default_wiki_branch")
errDb := repo_model.UpdateRepositoryColsNoAutoTime(ctx, &repo_model.Repository{ID: ctx.Repo.Repository.ID, DefaultWikiBranch: gitRepoDefaultBranch}, "default_wiki_branch")
if errDb != nil {
return wikiGitRepo, nil, errDb
}
Expand Down
2 changes: 1 addition & 1 deletion services/migrations/gitea_uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (g *GiteaLocalUploader) CreateRepo(ctx context.Context, repo *base.Reposito
return err
}
g.repo.ObjectFormatName = objectFormat.Name()
return repo_model.UpdateRepositoryCols(ctx, g.repo, "object_format_name")
return repo_model.UpdateRepositoryColsNoAutoTime(ctx, g.repo, "object_format_name")
}

// Close closes this uploader
Expand Down
2 changes: 1 addition & 1 deletion services/mirror/mirror_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func UpdateAddress(ctx context.Context, m *repo_model.Mirror, addr string) error
// erase authentication before storing in database
u.User = nil
m.Repo.OriginalURL = u.String()
return repo_model.UpdateRepositoryCols(ctx, m.Repo, "original_url")
return repo_model.UpdateRepositoryColsNoAutoTime(ctx, m.Repo, "original_url")
}

// mirrorSyncResult contains information of a updated reference.
Expand Down
6 changes: 3 additions & 3 deletions services/repository/avatar.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func UploadAvatar(ctx context.Context, repo *repo_model.Repository, data []byte)
// Users can upload the same image to other repo - prefix it with ID
// Then repo will be removed - only it avatar file will be removed
repo.Avatar = newAvatar
if err := repo_model.UpdateRepositoryCols(ctx, repo, "avatar"); err != nil {
if err := repo_model.UpdateRepositoryColsNoAutoTime(ctx, repo, "avatar"); err != nil {
return fmt.Errorf("UploadAvatar: Update repository avatar: %w", err)
}

Expand Down Expand Up @@ -77,7 +77,7 @@ func DeleteAvatar(ctx context.Context, repo *repo_model.Repository) error {
defer committer.Close()

repo.Avatar = ""
if err := repo_model.UpdateRepositoryCols(ctx, repo, "avatar"); err != nil {
if err := repo_model.UpdateRepositoryColsNoAutoTime(ctx, repo, "avatar"); err != nil {
return fmt.Errorf("DeleteAvatar: Update repository avatar: %w", err)
}

Expand Down Expand Up @@ -112,5 +112,5 @@ func generateAvatar(ctx context.Context, templateRepo, generateRepo *repo_model.
return err
}

return repo_model.UpdateRepositoryCols(ctx, generateRepo, "avatar")
return repo_model.UpdateRepositoryColsNoAutoTime(ctx, generateRepo, "avatar")
}
2 changes: 1 addition & 1 deletion services/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func updateRepository(ctx context.Context, repo *repo_model.Repository, visibili

e := db.GetEngine(ctx)

if _, err = e.ID(repo.ID).AllCols().Update(repo); err != nil {
if _, err = e.ID(repo.ID).NoAutoTime().AllCols().Update(repo); err != nil {
return fmt.Errorf("update: %w", err)
}

Expand Down
8 changes: 4 additions & 4 deletions services/repository/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func transferOwnership(ctx context.Context, doer *user_model.User, newOwnerName
repo.OwnerName = newOwner.Name

// Update repository.
if err := repo_model.UpdateRepositoryCols(ctx, repo, "owner_id", "owner_name"); err != nil {
if err := repo_model.UpdateRepositoryColsNoAutoTime(ctx, repo, "owner_id", "owner_name"); err != nil {
return fmt.Errorf("update owner: %w", err)
}

Expand Down Expand Up @@ -304,7 +304,7 @@ func transferOwnership(ctx context.Context, doer *user_model.User, newOwnerName
return fmt.Errorf("deleteRepositoryTransfer: %w", err)
}
repo.Status = repo_model.RepositoryReady
if err := repo_model.UpdateRepositoryCols(ctx, repo, "status"); err != nil {
if err := repo_model.UpdateRepositoryColsNoAutoTime(ctx, repo, "status"); err != nil {
return err
}

Expand Down Expand Up @@ -495,7 +495,7 @@ func RejectRepositoryTransfer(ctx context.Context, repo *repo_model.Repository,
}

repo.Status = repo_model.RepositoryReady
if err := repo_model.UpdateRepositoryCols(ctx, repo, "status"); err != nil {
if err := repo_model.UpdateRepositoryColsNoAutoTime(ctx, repo, "status"); err != nil {
return err
}

Expand Down Expand Up @@ -543,7 +543,7 @@ func CancelRepositoryTransfer(ctx context.Context, repoTransfer *repo_model.Repo
}

repoTransfer.Repo.Status = repo_model.RepositoryReady
if err := repo_model.UpdateRepositoryCols(ctx, repoTransfer.Repo, "status"); err != nil {
if err := repo_model.UpdateRepositoryColsNoAutoTime(ctx, repoTransfer.Repo, "status"); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion services/wiki/wiki.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ func ChangeDefaultWikiBranch(ctx context.Context, repo *repo_model.Repository, n
}
return db.WithTx(ctx, func(ctx context.Context) error {
repo.DefaultWikiBranch = newBranch
if err := repo_model.UpdateRepositoryCols(ctx, repo, "default_wiki_branch"); err != nil {
if err := repo_model.UpdateRepositoryColsNoAutoTime(ctx, repo, "default_wiki_branch"); err != nil {
return fmt.Errorf("unable to update database: %w", err)
}

Expand Down