···65656666// Release represents a release of repository.
6767type Release struct {
6868- ID int64 `xorm:"pk autoincr"`
6969- RepoID int64 `xorm:"INDEX UNIQUE(n)"`
7070- Repo *Repository `xorm:"-"`
7171- PublisherID int64 `xorm:"INDEX"`
7272- Publisher *user_model.User `xorm:"-"`
7373- TagName string `xorm:"INDEX UNIQUE(n)"`
7474- OriginalAuthor string
7575- OriginalAuthorID int64 `xorm:"index"`
7676- LowerTagName string
7777- Target string
7878- TargetBehind string `xorm:"-"` // to handle non-existing or empty target
7979- Title string
8080- Sha1 string `xorm:"VARCHAR(64)"`
8181- NumCommits int64
8282- NumCommitsBehind int64 `xorm:"-"`
8383- Note string `xorm:"TEXT"`
8484- RenderedNote template.HTML `xorm:"-"`
8585- IsDraft bool `xorm:"NOT NULL DEFAULT false"`
8686- IsPrerelease bool `xorm:"NOT NULL DEFAULT false"`
8787- IsTag bool `xorm:"NOT NULL DEFAULT false"` // will be true only if the record is a tag and has no related releases
8888- Attachments []*Attachment `xorm:"-"`
8989- CreatedUnix timeutil.TimeStamp `xorm:"INDEX"`
6868+ ID int64 `xorm:"pk autoincr"`
6969+ RepoID int64 `xorm:"INDEX UNIQUE(n)"`
7070+ Repo *Repository `xorm:"-"`
7171+ PublisherID int64 `xorm:"INDEX"`
7272+ Publisher *user_model.User `xorm:"-"`
7373+ TagName string `xorm:"INDEX UNIQUE(n)"`
7474+ OriginalAuthor string
7575+ OriginalAuthorID int64 `xorm:"index"`
7676+ LowerTagName string
7777+ Target string
7878+ TargetBehind string `xorm:"-"` // to handle non-existing or empty target
7979+ Title string
8080+ Sha1 string `xorm:"VARCHAR(64)"`
8181+ NumCommits int64
8282+ NumCommitsBehind int64 `xorm:"-"`
8383+ Note string `xorm:"TEXT"`
8484+ RenderedNote template.HTML `xorm:"-"`
8585+ IsDraft bool `xorm:"NOT NULL DEFAULT false"`
8686+ IsPrerelease bool `xorm:"NOT NULL DEFAULT false"`
8787+ IsTag bool `xorm:"NOT NULL DEFAULT false"` // will be true only if the record is a tag and has no related releases
8888+ Attachments []*Attachment `xorm:"-"`
8989+ CreatedUnix timeutil.TimeStamp `xorm:"INDEX"`
9090+ ArchiveDownloadCount *structs.TagArchiveDownloadCount `xorm:"-"`
9091}
91929293func init() {
···112113 }
113114 }
114115 }
116116+117117+ err = r.LoadArchiveDownloadCount(ctx)
118118+ if err != nil {
119119+ return err
120120+ }
121121+115122 return GetReleaseAttachments(ctx, r)
123123+}
124124+125125+// LoadArchiveDownloadCount loads the download count for the source archives
126126+func (r *Release) LoadArchiveDownloadCount(ctx context.Context) error {
127127+ var err error
128128+ r.ArchiveDownloadCount, err = GetArchiveDownloadCount(ctx, r.RepoID, r.ID)
129129+ return err
116130}
117131118132// APIURL the api url for a release. release must have attributes loaded
···445459 lowerTags := make([]string, 0, len(tags))
446460 for _, tag := range tags {
447461 lowerTags = append(lowerTags, strings.ToLower(tag))
462462+ }
463463+464464+ for _, tag := range tags {
465465+ release, err := GetRelease(ctx, repo.ID, tag)
466466+ if err != nil {
467467+ return fmt.Errorf("GetRelease: %w", err)
468468+ }
469469+470470+ err = DeleteArchiveDownloadCountForRelease(ctx, release.ID)
471471+ if err != nil {
472472+ return fmt.Errorf("DeleteTagArchiveDownloadCount: %w", err)
473473+ }
448474 }
449475450476 if _, err := db.GetEngine(ctx).
+9-7
modules/git/tag.go
···88 "sort"
99 "strings"
10101111+ api "code.gitea.io/gitea/modules/structs"
1112 "code.gitea.io/gitea/modules/util"
1213)
1314···20212122// Tag represents a Git tag.
2223type Tag struct {
2323- Name string
2424- ID ObjectID
2525- Object ObjectID // The id of this commit object
2626- Type string
2727- Tagger *Signature
2828- Message string
2929- Signature *ObjectSignature
2424+ Name string
2525+ ID ObjectID
2626+ Object ObjectID // The id of this commit object
2727+ Type string
2828+ Tagger *Signature
2929+ Message string
3030+ Signature *ObjectSignature
3131+ ArchiveDownloadCount *api.TagArchiveDownloadCount
3032}
31333234// Commit return the commit of the tag reference