From 63b3a33bf2f1de6318e269cfd0d9315472d796d2 Mon Sep 17 00:00:00 2001 From: Giteabot Date: Tue, 7 Jan 2025 07:55:04 +0800 Subject: [PATCH] fix empty repo updated time (#33120) (#33124) Backport #33120 by changchaishi fixes #33119 Co-authored-by: Chai-Shi Co-authored-by: wxiaoguang --- models/repo/update.go | 6 ++++++ routers/web/repo/view_home.go | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/models/repo/update.go b/models/repo/update.go index e7ca224028..fce357a1ac 100644 --- a/models/repo/update.go +++ b/models/repo/update.go @@ -46,6 +46,12 @@ func UpdateRepositoryCols(ctx context.Context, repo *Repository, cols ...string) return err } +// UpdateRepositoryColsNoAutoTime updates repository's columns and but applies time change automatically +func UpdateRepositoryColsNoAutoTime(ctx context.Context, repo *Repository, cols ...string) error { + _, err := db.GetEngine(ctx).ID(repo.ID).Cols(cols...).NoAutoTime().Update(repo) + return err +} + // ErrReachLimitOfRepo represents a "ReachLimitOfRepo" kind of error. type ErrReachLimitOfRepo struct { Limit int diff --git a/routers/web/repo/view_home.go b/routers/web/repo/view_home.go index a5b541f214..169c1a277f 100644 --- a/routers/web/repo/view_home.go +++ b/routers/web/repo/view_home.go @@ -224,11 +224,14 @@ func prepareRecentlyPushedNewBranches(ctx *context.Context) { } func updateContextRepoEmptyAndStatus(ctx *context.Context, empty bool, status repo_model.RepositoryStatus) { + if ctx.Repo.Repository.IsEmpty == empty && ctx.Repo.Repository.Status == status { + return + } ctx.Repo.Repository.IsEmpty = empty if ctx.Repo.Repository.Status == repo_model.RepositoryReady || ctx.Repo.Repository.Status == repo_model.RepositoryBroken { ctx.Repo.Repository.Status = status // only handle ready and broken status, leave other status as-is } - if err := repo_model.UpdateRepositoryCols(ctx, ctx.Repo.Repository, "is_empty", "status"); err != nil { + if err := repo_model.UpdateRepositoryColsNoAutoTime(ctx, ctx.Repo.Repository, "is_empty", "status"); err != nil { ctx.ServerError("updateContextRepoEmptyAndStatus: UpdateRepositoryCols", err) return }