tianxiaoliang commented on a change in pull request #911:
URL: 
https://github.com/apache/servicecomb-service-center/pull/911#discussion_r608315330



##########
File path: datasource/mongo/client/dao/dep.go
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package dao
+
+import (
+       "context"
+       "github.com/apache/servicecomb-service-center/datasource"
+       "github.com/apache/servicecomb-service-center/datasource/mongo/client"
+       
"github.com/apache/servicecomb-service-center/datasource/mongo/client/model"
+       "github.com/apache/servicecomb-service-center/datasource/mongo/sd"
+       mutil 
"github.com/apache/servicecomb-service-center/datasource/mongo/util"
+       "github.com/apache/servicecomb-service-center/pkg/util"
+       "github.com/go-chassis/cari/discovery"
+)
+
+const (
+       p = "p"
+       c = "c"
+)
+
+func GetProviderServiceOfDeps(ctx context.Context, provider 
*discovery.MicroService) (*discovery.MicroServiceDependency, error) {
+       res := sd.Store().Dep().Cache().GetValue(genDepserivceKey(p, provider))
+       cacheServiceKeys, ok := processCacheDep(res)
+       if !ok || len(cacheServiceKeys) == 0 {
+               return GetServiceofDepsFromDB(ctx, p, provider)
+       }
+       return cacheServiceKeys[0], nil
+}
+
+func processCacheDep(cache []interface{}) 
([]*discovery.MicroServiceDependency, bool) {
+       res := make([]*discovery.MicroServiceDependency, 0, len(cache))
+       for _, v := range cache {
+               t, ok := v.(model.DependencyRule)
+               if !ok {
+                       return nil, false
+               }
+               res = append(res, t.Dep)
+       }
+       return res, true
+}
+
+func GetServiceofDepsFromDB(ctx context.Context, ruleType string, provider 
*discovery.MicroService) (*discovery.MicroServiceDependency, error) {
+       filter := mutil.NewFilter(
+               mutil.ServiceType(ruleType),
+               mutil.ServiceKeyTenant(util.ParseDomainProject(ctx)),
+               mutil.ServiceKeyAppID(provider.AppId),
+               mutil.ServiceKeyServiceName(provider.ServiceName),
+               mutil.ServiceKeyServiceVersion(provider.Version),
+       )
+       depRule, err := getDeps(ctx, filter)
+       if err != nil {
+               return nil, err
+       }
+       return depRule.Dep, nil
+}
+
+func genDepserivceKey(ruleType string, service *discovery.MicroService) string 
{
+       return util.StringJoin([]string{ruleType, service.AppId, 
service.ServiceName, service.Version}, "/")

Review comment:
       这个util包里的方法没有意义,go自带这个func,没有什么特别的优势就干掉吧




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to