diff options
author | 6543 <6543@obermui.de> | 2021-03-19 20:01:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-19 21:01:24 +0200 |
commit | a3a65137ba89267b5145825b21bb90257ee9f2f0 (patch) | |
tree | 21ee8477706d9f7d7a0f35185e83aa86bfa6d61d /models/repo.go | |
parent | dace0ce1b191d060976bac08f181ca768fc027a0 (diff) | |
download | gitea-a3a65137ba89267b5145825b21bb90257ee9f2f0.tar.gz gitea-a3a65137ba89267b5145825b21bb90257ee9f2f0.zip |
Delete Labels & IssueLabels on Repo Delete too (#15039)
* Doctor: find IssueLabels without existing label
* on Repo Delete: delete labels & issue_labels too
* performance nits
* Add Migration: Delete orphaned IssueLabels
* Migration v174: use Sync2
* USE sess !!!
* better func name
* code format & comment
* RAW SQL
* Update models/migrations/v176.go
* next try?
Diffstat (limited to 'models/repo.go')
-rw-r--r-- | models/repo.go | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/models/repo.go b/models/repo.go index 15d6351251..329e63cc42 100644 --- a/models/repo.go +++ b/models/repo.go @@ -1447,11 +1447,11 @@ func DeleteRepository(doer *User, uid, repoID int64) error { releaseAttachments = append(releaseAttachments, attachments[i].RelativePath()) } - if _, err = sess.Exec("UPDATE `user` SET num_stars=num_stars-1 WHERE id IN (SELECT `uid` FROM `star` WHERE repo_id = ?)", repo.ID); err != nil { + if _, err := sess.Exec("UPDATE `user` SET num_stars=num_stars-1 WHERE id IN (SELECT `uid` FROM `star` WHERE repo_id = ?)", repo.ID); err != nil { return err } - if err = deleteBeans(sess, + if err := deleteBeans(sess, &Access{RepoID: repo.ID}, &Action{RepoID: repo.ID}, &Watch{RepoID: repoID}, @@ -1475,28 +1475,33 @@ func DeleteRepository(doer *User, uid, repoID int64) error { return fmt.Errorf("deleteBeans: %v", err) } + // Delete Labels and related objects + if err := deleteLabelsByRepoID(sess, repoID); err != nil { + return err + } + // Delete Issues and related objects var attachmentPaths []string if attachmentPaths, err = deleteIssuesByRepoID(sess, repoID); err != nil { return err } - if _, err = sess.Where("repo_id = ?", repoID).Delete(new(RepoUnit)); err != nil { + if _, err := sess.Where("repo_id = ?", repoID).Delete(new(RepoUnit)); err != nil { return err } if repo.IsFork { - if _, err = sess.Exec("UPDATE `repository` SET num_forks=num_forks-1 WHERE id=?", repo.ForkID); err != nil { + if _, err := sess.Exec("UPDATE `repository` SET num_forks=num_forks-1 WHERE id=?", repo.ForkID); err != nil { return fmt.Errorf("decrease fork count: %v", err) } } - if _, err = sess.Exec("UPDATE `user` SET num_repos=num_repos-1 WHERE id=?", uid); err != nil { + if _, err := sess.Exec("UPDATE `user` SET num_repos=num_repos-1 WHERE id=?", uid); err != nil { return err } if len(repo.Topics) > 0 { - if err = removeTopicsFromRepo(sess, repo.ID); err != nil { + if err := removeTopicsFromRepo(sess, repo.ID); err != nil { return err } } |