mirror of
https://github.com/goharbor/harbor.git
synced 2025-01-09 17:37:44 +01:00
1.search refactor due to storing repositories in database 2.bug fix: filter repositories in project view
This commit is contained in:
parent
bc52b212cf
commit
ce3c3fe8f1
@ -22,7 +22,6 @@ import (
|
|||||||
|
|
||||||
"github.com/vmware/harbor/dao"
|
"github.com/vmware/harbor/dao"
|
||||||
"github.com/vmware/harbor/models"
|
"github.com/vmware/harbor/models"
|
||||||
"github.com/vmware/harbor/service/cache"
|
|
||||||
"github.com/vmware/harbor/utils"
|
"github.com/vmware/harbor/utils"
|
||||||
"github.com/vmware/harbor/utils/log"
|
"github.com/vmware/harbor/utils/log"
|
||||||
)
|
)
|
||||||
@ -85,11 +84,17 @@ func (s *SearchAPI) Get() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories, err2 := cache.GetRepoFromCache()
|
repos, err := dao.GetAllRepositories()
|
||||||
if err2 != nil {
|
if err != nil {
|
||||||
log.Errorf("Failed to get repos from cache, error: %v", err2)
|
log.Errorf("failed to list repositories: %v", err)
|
||||||
s.CustomAbort(http.StatusInternalServerError, "Failed to get repositories search result")
|
s.CustomAbort(http.StatusInternalServerError, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
repositories := []string{}
|
||||||
|
for _, repo := range repos {
|
||||||
|
repositories = append(repositories, repo.Name)
|
||||||
|
}
|
||||||
|
|
||||||
sort.Strings(repositories)
|
sort.Strings(repositories)
|
||||||
repositoryResult := filterRepositories(repositories, projects, keyword)
|
repositoryResult := filterRepositories(repositories, projects, keyword)
|
||||||
result := &searchResult{Project: projectResult, Repository: repositoryResult}
|
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
|
needMatchKeyword := len(keyword) > 0 && len(keyword[0]) != 0
|
||||||
|
|
||||||
for _, repo := range repos {
|
for _, repo := range repos {
|
||||||
if needMatchKeyword &&
|
if needMatchKeyword &&
|
||||||
strings.Contains(repo.Name, keyword[0]) {
|
!strings.Contains(repo.Name, keyword[0]) {
|
||||||
repositories = append(repositories, repo.Name)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user