Skip to content

Commit

Permalink
small optimization for get issue labels
Browse files Browse the repository at this point in the history
  • Loading branch information
lunny authored and bkcsoft committed Feb 12, 2017
1 parent 3f67676 commit d76f34e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
21 changes: 4 additions & 17 deletions models/issue_label.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,23 +190,10 @@ func GetLabelsByRepoID(repoID int64, sortType string) ([]*Label, error) {
}

func getLabelsByIssueID(e Engine, issueID int64) ([]*Label, error) {
issueLabels, err := getIssueLabels(e, issueID)
if err != nil {
return nil, fmt.Errorf("getIssueLabels: %v", err)
} else if len(issueLabels) == 0 {
return []*Label{}, nil
}

labelIDs := make([]int64, len(issueLabels))
for i := range issueLabels {
labelIDs[i] = issueLabels[i].LabelID
}

labels := make([]*Label, 0, len(labelIDs))
return labels, e.
Where("id > 0").
In("id", labelIDs).
Asc("name").
var labels []*Label
return labels, e.Where("issue_label.issue_id = ?", issueID).
Join("LEFT", "issue_label", "issue_label.label_id = label.id").
Asc("label.name").
Find(&labels)
}

Expand Down
1 change: 1 addition & 0 deletions models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type Engine interface {
Insert(...interface{}) (int64, error)
InsertOne(interface{}) (int64, error)
Iterate(interface{}, xorm.IterFunc) error
Join(joinOperator string, tablename interface{}, condition string, args ...interface{}) *xorm.Session
SQL(interface{}, ...interface{}) *xorm.Session
Where(interface{}, ...interface{}) *xorm.Session
}
Expand Down

0 comments on commit d76f34e

Please sign in to comment.