summaryrefslogtreecommitdiffstats
path: root/models/repo
diff options
context:
space:
mode:
authorGiteabot <teabot@gitea.io>2024-01-31 12:23:26 +0800
committerGitHub <noreply@github.com>2024-01-31 04:23:26 +0000
commit2048363f9ed6de485a81afa980ed90bf916bb3b8 (patch)
treed7257ebb4df655664f2ba45142ca433291f7221a /models/repo
parentb8e6cffd317401d980600e339eb21b15b9bc64c1 (diff)
downloadgitea-2048363f9ed6de485a81afa980ed90bf916bb3b8.tar.gz
gitea-2048363f9ed6de485a81afa980ed90bf916bb3b8.zip
Don't remove all mirror repository's releases when mirroring (#28817) (#28939)
Backport #28817 by @lunny Fix #22066 # Purpose This PR fix the releases will be deleted when mirror repository sync the tags. # The problem In the previous implementation of #19125. All releases record in databases of one mirror repository will be deleted before sync. Ref: https://github.com/go-gitea/gitea/pull/19125/files#diff-2aa04998a791c30e5a02b49a97c07fcd93d50e8b31640ce2ddb1afeebf605d02R481 # The Pros This PR introduced a new method which will load all releases from databases and all tags on git data into memory. And detect which tags needs to be inserted, which tags need to be updated or deleted. Only tags releases(IsTag=true) which are not included in git data will be deleted, only tags which sha1 changed will be updated. So it will not delete any real releases include drafts. # The Cons The drawback is the memory usage will be higher than before if there are many tags on this repository. This PR defined a special release struct to reduce columns loaded from database to memory. --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'models/repo')
-rw-r--r--models/repo/release.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/models/repo/release.go b/models/repo/release.go
index 223d3f2501..067de8a313 100644
--- a/models/repo/release.go
+++ b/models/repo/release.go
@@ -230,12 +230,18 @@ type FindReleasesOptions struct {
IsPreRelease util.OptionalBool
IsDraft util.OptionalBool
TagNames []string
+ RepoID int64
HasSha1 util.OptionalBool // useful to find draft releases which are created with existing tags
}
func (opts *FindReleasesOptions) toConds(repoID int64) builder.Cond {
+ opts.RepoID = repoID
+ return opts.ToConds()
+}
+
+func (opts *FindReleasesOptions) ToConds() builder.Cond {
cond := builder.NewCond()
- cond = cond.And(builder.Eq{"repo_id": repoID})
+ cond = cond.And(builder.Eq{"repo_id": opts.RepoID})
if !opts.IncludeDrafts {
cond = cond.And(builder.Eq{"is_draft": false})