diff --git a/api/search.go b/api/search.go index c783c11a1..e12cd2383 100644 --- a/api/search.go +++ b/api/search.go @@ -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} diff --git a/api/utils.go b/api/utils.go index 08423dd1a..83f1f508d 100644 --- a/api/utils.go +++ b/api/utils.go @@ -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 }