Apply suggestion

This commit is contained in:
Chongyi Zheng 2024-02-25 19:29:53 -05:00
parent 77fd657b0a
commit 18fffc0a06
No known key found for this signature in database
GPG Key ID: 4B90B77407DA2359
1 changed files with 2 additions and 7 deletions

View File

@ -937,18 +937,13 @@ func UpsertIssues(ctx context.Context, issues ...*Issue) error {
func upsertIssue(ctx context.Context, issue *Issue) (isInsert bool, err error) {
sess := db.GetEngine(ctx)
var issueIDs []int64
err = sess.Table("issue").Where("repo_id = ? AND `index` = ?", issue.RepoID, issue.Index).Cols("id").Find(&issueIDs)
has, err := sess.Table("issue").Where("repo_id = ? AND `index` = ?", issue.RepoID, issue.Index).Cols("id").Get(&issue.ID)
if err != nil {
return false, err
}
if len(issueIDs) == 0 {
if !has {
return true, insertIssue(ctx, issue)
}
issue.ID = issueIDs[0]
return false, updateIssue(ctx, issue)
}