Browse Source

fix: 500 error on /explore/repos page. (#946)

Bo-Yi Wu 3 years ago
parent
commit
a31f64d639
2 changed files with 21 additions and 23 deletions
  1. 14 17
      models/repo.go
  2. 7 6
      routers/user/profile.go

+ 14 - 17
models/repo.go

@@ -1198,10 +1198,8 @@ func Repositories(opts *SearchRepoOptions) (_ RepositoryList, err error) {
1198 1198
 		return nil, fmt.Errorf("Repo: %v", err)
1199 1199
 	}
1200 1200
 
1201
-	if opts.Searcher != nil || opts.Starred {
1202
-		if err = repos.loadAttributes(x); err != nil {
1203
-			return nil, fmt.Errorf("LoadAttributes: %v", err)
1204
-		}
1201
+	if err = repos.loadAttributes(x); err != nil {
1202
+		return nil, fmt.Errorf("LoadAttributes: %v", err)
1205 1203
 	}
1206 1204
 
1207 1205
 	return repos, nil
@@ -1743,10 +1741,8 @@ func GetRecentUpdatedRepositories(opts *SearchRepoOptions) (repos RepositoryList
1743 1741
 		return nil, fmt.Errorf("Repo: %v", err)
1744 1742
 	}
1745 1743
 
1746
-	if opts.Searcher != nil || opts.Starred {
1747
-		if err = repos.loadAttributes(x); err != nil {
1748
-			return nil, fmt.Errorf("LoadAttributes: %v", err)
1749
-		}
1744
+	if err = repos.loadAttributes(x); err != nil {
1745
+		return nil, fmt.Errorf("LoadAttributes: %v", err)
1750 1746
 	}
1751 1747
 
1752 1748
 	return repos, nil
@@ -1781,14 +1777,15 @@ func GetPrivateRepositoryCount(u *User) (int64, error) {
1781 1777
 
1782 1778
 // SearchRepoOptions holds the search options
1783 1779
 type SearchRepoOptions struct {
1784
-	Keyword  string
1785
-	OwnerID  int64
1786
-	Searcher *User //ID of the person who's seeking
1787
-	OrderBy  string
1788
-	Private  bool // Include private repositories in results
1789
-	Starred  bool
1790
-	Page     int
1791
-	PageSize int // Can be smaller than or equal to setting.ExplorePagingNum
1780
+	Keyword   string
1781
+	OwnerID   int64
1782
+	Searcher  *User //ID of the person who's seeking
1783
+	OrderBy   string
1784
+	Private   bool // Include private repositories in results
1785
+	Starred   bool
1786
+	Page      int
1787
+	IsProfile bool
1788
+	PageSize  int // Can be smaller than or equal to setting.ExplorePagingNum
1792 1789
 }
1793 1790
 
1794 1791
 // SearchRepositoryByName takes keyword and part of repository name to search,
@@ -1856,7 +1853,7 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos RepositoryList, _ in
1856 1853
 		return nil, 0, fmt.Errorf("Repo: %v", err)
1857 1854
 	}
1858 1855
 
1859
-	if opts.Searcher != nil || opts.Starred {
1856
+	if !opts.IsProfile {
1860 1857
 		if err = repos.loadAttributes(x); err != nil {
1861 1858
 			return nil, 0, fmt.Errorf("LoadAttributes: %v", err)
1862 1859
 		}

+ 7 - 6
routers/user/profile.go

@@ -192,12 +192,13 @@ func Profile(ctx *context.Context) {
192 192
 			ctx.Data["Total"] = total
193 193
 		} else {
194 194
 			repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{
195
-				Keyword:  keyword,
196
-				OwnerID:  ctxUser.ID,
197
-				OrderBy:  orderBy,
198
-				Private:  showPrivate,
199
-				Page:     page,
200
-				PageSize: setting.UI.User.RepoPagingNum,
195
+				Keyword:   keyword,
196
+				OwnerID:   ctxUser.ID,
197
+				OrderBy:   orderBy,
198
+				Private:   showPrivate,
199
+				Page:      page,
200
+				IsProfile: true,
201
+				PageSize:  setting.UI.User.RepoPagingNum,
201 202
 			})
202 203
 			if err != nil {
203 204
 				ctx.Handle(500, "SearchRepositoryByName", err)