mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-03 22:52:28 +01:00
Fix repository deletion when there is large number of issues in it (#5426)
This commit is contained in:
parent
c8a9384a70
commit
f80b4f46ae
1 changed files with 40 additions and 39 deletions
|
@ -32,6 +32,7 @@ import (
|
||||||
|
|
||||||
"github.com/Unknwon/cae/zip"
|
"github.com/Unknwon/cae/zip"
|
||||||
"github.com/Unknwon/com"
|
"github.com/Unknwon/com"
|
||||||
|
"github.com/go-xorm/builder"
|
||||||
"github.com/go-xorm/xorm"
|
"github.com/go-xorm/xorm"
|
||||||
"github.com/mcuadros/go-version"
|
"github.com/mcuadros/go-version"
|
||||||
"gopkg.in/ini.v1"
|
"gopkg.in/ini.v1"
|
||||||
|
@ -1774,37 +1775,37 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
|
||||||
return fmt.Errorf("deleteBeans: %v", err)
|
return fmt.Errorf("deleteBeans: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete comments and attachments.
|
deleteCond := builder.Select("id").From("issue").Where(builder.Eq{"repo_id": repoID})
|
||||||
issueIDs := make([]int64, 0, 25)
|
// Delete comments and attachments
|
||||||
attachmentPaths := make([]string, 0, len(issueIDs))
|
if _, err = sess.In("issue_id", deleteCond).
|
||||||
if err = sess.
|
Delete(&Comment{}); err != nil {
|
||||||
Table("issue").
|
|
||||||
Cols("id").
|
|
||||||
Where("repo_id=?", repoID).
|
|
||||||
Find(&issueIDs); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(issueIDs) > 0 {
|
if _, err = sess.In("issue_id", deleteCond).
|
||||||
if _, err = sess.In("issue_id", issueIDs).Delete(&Comment{}); err != nil {
|
Delete(&IssueUser{}); err != nil {
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err = sess.In("issue_id", issueIDs).Delete(&IssueUser{}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err = sess.In("issue_id", issueIDs).Delete(&Reaction{}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err = sess.In("issue_id", issueIDs).Delete(&IssueWatch{}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err = sess.In("issue_id", issueIDs).Delete(&Stopwatch{}); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
attachments := make([]*Attachment, 0, 5)
|
if _, err = sess.In("issue_id", deleteCond).
|
||||||
if err = sess.
|
Delete(&Reaction{}); err != nil {
|
||||||
In("issue_id", issueIDs).
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err = sess.In("issue_id", deleteCond).
|
||||||
|
Delete(&IssueWatch{}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err = sess.In("issue_id", deleteCond).
|
||||||
|
Delete(&Stopwatch{}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
attachmentPaths := make([]string, 0, 20)
|
||||||
|
attachments := make([]*Attachment, 0, len(attachmentPaths))
|
||||||
|
if err = sess.Join("INNER", "issue", "issue.id = attachment.issue_id").
|
||||||
|
Where("issue.repo_id = ?", repoID).
|
||||||
Find(&attachments); err != nil {
|
Find(&attachments); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1812,14 +1813,14 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
|
||||||
attachmentPaths = append(attachmentPaths, attachments[j].LocalPath())
|
attachmentPaths = append(attachmentPaths, attachments[j].LocalPath())
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = sess.In("issue_id", issueIDs).Delete(&Attachment{}); err != nil {
|
if _, err = sess.In("issue_id", deleteCond).
|
||||||
|
Delete(&Attachment{}); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err = sess.Delete(&Issue{RepoID: repoID}); err != nil {
|
if _, err = sess.Delete(&Issue{RepoID: repoID}); err != nil {
|
||||||
return err
|
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
|
return err
|
||||||
|
|
Loading…
Reference in a new issue