mirror of
https://github.com/goharbor/harbor.git
synced 2025-01-09 09:27:42 +01:00
Merge pull request #766 from ywk253100/search
Search refactor and bug fix
This commit is contained in:
commit
8788963f88
@ -22,7 +22,6 @@ import (
|
||||
|
||||
"github.com/vmware/harbor/dao"
|
||||
"github.com/vmware/harbor/models"
|
||||
"github.com/vmware/harbor/service/cache"
|
||||
"github.com/vmware/harbor/utils"
|
||||
"github.com/vmware/harbor/utils/log"
|
||||
)
|
||||
@ -85,11 +84,17 @@ func (s *SearchAPI) Get() {
|
||||
}
|
||||
}
|
||||
|
||||
repositories, err2 := cache.GetRepoFromCache()
|
||||
if err2 != nil {
|
||||
log.Errorf("Failed to get repos from cache, error: %v", err2)
|
||||
s.CustomAbort(http.StatusInternalServerError, "Failed to get repositories search result")
|
||||
repos, err := dao.GetAllRepositories()
|
||||
if err != nil {
|
||||
log.Errorf("failed to list repositories: %v", err)
|
||||
s.CustomAbort(http.StatusInternalServerError, "")
|
||||
}
|
||||
|
||||
repositories := []string{}
|
||||
for _, repo := range repos {
|
||||
repositories = append(repositories, repo.Name)
|
||||
}
|
||||
|
||||
sort.Strings(repositories)
|
||||
repositoryResult := filterRepositories(repositories, projects, keyword)
|
||||
result := &searchResult{Project: projectResult, Repository: repositoryResult}
|
||||
|
@ -477,10 +477,10 @@ func getReposByProject(name string, keyword ...string) ([]string, error) {
|
||||
}
|
||||
|
||||
needMatchKeyword := len(keyword) > 0 && len(keyword[0]) != 0
|
||||
|
||||
for _, repo := range repos {
|
||||
if needMatchKeyword &&
|
||||
strings.Contains(repo.Name, keyword[0]) {
|
||||
repositories = append(repositories, repo.Name)
|
||||
!strings.Contains(repo.Name, keyword[0]) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user