Load repository when searching
parent
da61367c19
commit
9fa0822570
|
@ -22,6 +22,7 @@ type Commit struct {
|
|||
CommitterEmail string
|
||||
CommitterName string
|
||||
CommitterTime time.Time
|
||||
Repo *Repository `xorm:"-"`
|
||||
}
|
||||
|
||||
func FulltextSearchCommits(q string) ([]*Commit, error) {
|
||||
|
@ -31,5 +32,27 @@ func FulltextSearchCommits(q string) ([]*Commit, error) {
|
|||
if err := sess.Find(&commits); err != nil {
|
||||
return nil, fmt.Errorf("Find: %v", err)
|
||||
}
|
||||
if len(commits) == 0 {
|
||||
return commits, nil
|
||||
}
|
||||
// Load repositories
|
||||
set := make(map[int64]*Repository)
|
||||
for i := range commits {
|
||||
set[commits[i].RepoID] = nil
|
||||
}
|
||||
ids := make([]int64, 0, len(set))
|
||||
for i := range set {
|
||||
ids = append(ids, i)
|
||||
}
|
||||
repos := make([]*Repository, 0, len(ids))
|
||||
if err := sess.In("id", ids).Find(&repos); err != nil {
|
||||
return nil, fmt.Errorf("find users: %v", err)
|
||||
}
|
||||
for i := range repos {
|
||||
set[repos[i].ID] = repos[i]
|
||||
}
|
||||
for i := range commits {
|
||||
commits[i].Repo = set[repos[i].RepoID]
|
||||
}
|
||||
return commits, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue