little-cui commented on code in PR #294:
URL: https://github.com/apache/servicecomb-kie/pull/294#discussion_r1307095096


##########
server/pubsub/notifier/kv.go:
##########
@@ -75,15 +75,14 @@ func (h *KVHandler) FindTopicAndFire(ke 
*pubsub.KVChangeEvent) {
                        return true
                }
                if t.Match(ke) {
-                       prepareCache(key.(string), t)
                        notifyAndRemoveObservers(value, ke)
                }
                return true
        })
 }
 
-func prepareCache(topicName string, topic *pubsub.Topic) {
-       rev, kvs, err := kvsvc.ListKV(context.TODO(), &model.ListKVRequest{
+func PrepareCache(topicName string, topic *pubsub.Topic, ctx context.Context) {

Review Comment:
   既然抽到外层,这个方法也需要抽取到外层



##########
server/resource/v1/kv_resource.go:
##########
@@ -262,12 +262,14 @@ func isLegalWaitRequest(rctx *restful.Context, request 
*model.ListKVRequest) boo
        return true
 }
 func watch(rctx *restful.Context, request *model.ListKVRequest, wait string) 
bool {
+       ctx, cancel := context.WithCancel(rctx.Ctx)
+       defer cancel()

Review Comment:
   增加cancel是什么原因?



##########
server/pubsub/notifier/kv.go:
##########
@@ -75,15 +75,14 @@ func (h *KVHandler) FindTopicAndFire(ke 
*pubsub.KVChangeEvent) {
                        return true
                }
                if t.Match(ke) {
-                       prepareCache(key.(string), t)
                        notifyAndRemoveObservers(value, ke)
                }
                return true
        })
 }
 
-func prepareCache(topicName string, topic *pubsub.Topic) {
-       rev, kvs, err := kvsvc.ListKV(context.TODO(), &model.ListKVRequest{
+func PrepareCache(topicName string, topic *pubsub.Topic, ctx context.Context) {

Review Comment:
   既然抽到外层,这个方法也需要抽取到外层



##########
server/resource/v1/kv_resource.go:
##########
@@ -262,12 +262,14 @@ func isLegalWaitRequest(rctx *restful.Context, request 
*model.ListKVRequest) boo
        return true
 }
 func watch(rctx *restful.Context, request *model.ListKVRequest, wait string) 
bool {
+       ctx, cancel := context.WithCancel(rctx.Ctx)
+       defer cancel()

Review Comment:
   增加cancel是什么原因?



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to