diff options
author | 6543 <6543@obermui.de> | 2020-04-17 19:42:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-17 20:42:57 +0300 |
commit | 12960b9d1861c9e7b0b5c7076dec029de80a1944 (patch) | |
tree | 1be5df2d4ba6829a6bc066cede732c1f77373cd4 /models | |
parent | 0010fde8a2c813b02b78c8c806716f9725b3b6c3 (diff) | |
download | gitea-12960b9d1861c9e7b0b5c7076dec029de80a1944.tar.gz gitea-12960b9d1861c9e7b0b5c7076dec029de80a1944.zip |
[BugFix] remove nil inserts in models (#11096)
* Fix InsertReleases Nil Insert on Attachments
* FIX "No element on slice when insert" & smal refactor
* again
* impruve
* rm useles newline
* Apply suggestions from code review
Co-Authored-By: zeripath <art27@cantab.net>
* process insert as a whole
Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'models')
-rw-r--r-- | models/migrate.go | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/models/migrate.go b/models/migrate.go index ea4a8c1768..2715c5bd9b 100644 --- a/models/migrate.go +++ b/models/migrate.go @@ -64,15 +64,20 @@ func insertIssue(sess *xorm.Session, issue *Issue) error { }) labelIDs = append(labelIDs, label.ID) } - if _, err := sess.Insert(issueLabels); err != nil { - return err + if len(issueLabels) > 0 { + if _, err := sess.Insert(issueLabels); err != nil { + return err + } } for _, reaction := range issue.Reactions { reaction.IssueID = issue.ID } - if _, err := sess.Insert(issue.Reactions); err != nil { - return err + + if len(issue.Reactions) > 0 { + if _, err := sess.Insert(issue.Reactions); err != nil { + return err + } } cols := make([]string, 0) @@ -151,8 +156,10 @@ func InsertIssueComments(comments []*Comment) error { reaction.IssueID = comment.IssueID reaction.CommentID = comment.ID } - if _, err := sess.Insert(comment.Reactions); err != nil { - return err + if len(comment.Reactions) > 0 { + if _, err := sess.Insert(comment.Reactions); err != nil { + return err + } } } @@ -196,12 +203,14 @@ func InsertReleases(rels ...*Release) error { return err } - for i := 0; i < len(rel.Attachments); i++ { - rel.Attachments[i].ReleaseID = rel.ID - } + if len(rel.Attachments) > 0 { + for i := range rel.Attachments { + rel.Attachments[i].ReleaseID = rel.ID + } - if _, err := sess.NoAutoTime().Insert(rel.Attachments); err != nil { - return err + if _, err := sess.NoAutoTime().Insert(rel.Attachments); err != nil { + return err + } } } |