This is an automated email from the ASF dual-hosted git repository.

tianxiaoliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-service-center.git


The following commit(s) were added to refs/heads/master by this push:
     new c106fc1  Ignore share services in both service list and provider list 
(#691)
c106fc1 is described below

commit c106fc1760e8cc8e684790e31ff08c192e237a68
Author: humingcheng <[email protected]>
AuthorDate: Fri Sep 11 17:00:55 2020 +0800

    Ignore share services in both service list and provider list (#691)
---
 server/rest/govern/controller_v4.go | 46 ++++++++++++++++++++++---------------
 1 file changed, 28 insertions(+), 18 deletions(-)

diff --git a/server/rest/govern/controller_v4.go 
b/server/rest/govern/controller_v4.go
index 561eacb..c73bf03 100644
--- a/server/rest/govern/controller_v4.go
+++ b/server/rest/govern/controller_v4.go
@@ -67,7 +67,7 @@ func (governService *ResourceV4) GetGraph(w 
http.ResponseWriter, r *http.Request
        }
        nodes := make([]Node, 0, len(services))
        for _, service := range services {
-               if !withShared && 
core.IsShared(proto.MicroServiceToKey(domainProject, service)) {
+               if governService.isSkipped(withShared, domainProject, service) {
                        continue
                }
 
@@ -92,27 +92,37 @@ func (governService *ResourceV4) GetGraph(w 
http.ResponseWriter, r *http.Request
                }
 
                providers := proResp.Providers
-               countInner := len(providers)
-               if countInner <= 0 {
+               lines := governService.genLinesFromNode(withShared, 
domainProject, node, providers)
+               graph.Lines = append(graph.Lines, lines...)
+       }
+       graph.Nodes = nodes
+       controller.WriteResponse(w, nil, graph)
+}
+
+func (governService *ResourceV4) genLinesFromNode(withShared bool, 
domainProject string, node Node, providers []*pb.MicroService) []Line {
+       lines := make([]Line, 0)
+       for _, child := range providers {
+               if child == nil {
                        continue
                }
-               for _, child := range providers {
-                       if child == nil {
-                               continue
-                       }
-
-                       if service.ServiceId == child.ServiceId {
-                               continue
-                       }
-                       line := Line{}
-                       line.From = node
-                       line.To.Name = child.ServiceName
-                       line.To.ID = child.ServiceId
-                       graph.Lines = append(graph.Lines, line)
+
+               if node.ID == child.ServiceId {
+                       continue
                }
+               if governService.isSkipped(withShared, domainProject, child) {
+                       continue
+               }
+               line := Line{}
+               line.From = node
+               line.To.Name = child.ServiceName
+               line.To.ID = child.ServiceId
+               lines = append(lines, line)
        }
-       graph.Nodes = nodes
-       controller.WriteResponse(w, nil, graph)
+       return lines
+}
+
+func (governService *ResourceV4) isSkipped(withShared bool, domainProject 
string, service *pb.MicroService) bool {
+       return !withShared && 
core.IsShared(proto.MicroServiceToKey(domainProject, service))
 }
 
 // GetServiceDetail 查询服务详细信息

Reply via email to