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



##########
File path: datasource/mongo/client/dao/rule.go
##########
@@ -29,6 +32,32 @@ import (
        "github.com/apache/servicecomb-service-center/pkg/log"
 )
 
+func GetRulesByServiceID(ctx context.Context, serviceID string) 
([]*model.Rule, error) {
+       cacheRes := sd.Store().Rule().Cache().GetValue(serviceID)
+       cacheRules, ok := processCacheRules(cacheRes)
+       if !ok || len(cacheRules) == 0 {
+               return GetRules(ctx, 
mutil.NewDomainProjectFilter(util.ParseDomain(ctx), util.ParseDomain(ctx), 
mutil.ServiceID(serviceID)))
+       }
+       return cacheRules, nil
+}
+
+func processCacheRules(cacheRules []interface{}) ([]*model.Rule, bool) {
+       res := make([]*model.Rule, 0, len(cacheRules))
+       for _, v := range cacheRules {
+               t, ok := v.(model.Rule)

Review comment:
       这里判断其实很频繁,封一个统一的cache API吧 参考下go chassis 
https://github.com/go-chassis/go-chassis/commit/6f8d8843fabdec93d8fd633ffe4e2b64314d1329
   
   core/registry/cache.go 理想情况就是etcd,mongo用的同一套cache API,先通过mongbo实现把API定义好




-- 
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:
[email protected]


Reply via email to