ソースを参照

fix cache reference issue

abhishek9686 1 年間 前
コミット
8efd193db7
1 ファイル変更6 行追加3 行削除
  1. 6 3
      controllers/hosts.go

+ 6 - 3
controllers/hosts.go

@@ -79,7 +79,7 @@ func upgradeHost(w http.ResponseWriter, r *http.Request) {
 // @Success     200 {array} models.ApiHost
 // @Failure     500 {object} models.ErrorResponse
 func getHosts(w http.ResponseWriter, r *http.Request) {
-
+	w.Header().Set("Content-Type", "application/json")
 	currentHosts := []models.Host{}
 	username := r.Header.Get("user")
 	user, err := logic.GetUser(username)
@@ -90,7 +90,7 @@ func getHosts(w http.ResponseWriter, r *http.Request) {
 	if err != nil {
 		return
 	}
-
+	respHostsMap := make(map[string]struct{})
 	if !userPlatformRole.FullAccess {
 		nodes, err := logic.GetAllNodes()
 		if err != nil {
@@ -107,9 +107,12 @@ func getHosts(w http.ResponseWriter, r *http.Request) {
 				return
 			}
 			for _, node := range filteredNodes {
+				if _, ok := respHostsMap[node.HostID.String()]; ok {
+					continue
+				}
 				if host, ok := currentHostsMap[node.HostID.String()]; ok {
 					currentHosts = append(currentHosts, host)
-					delete(currentHostsMap, host.ID.String())
+					respHostsMap[host.ID.String()] = struct{}{}
 				}
 			}