nic-6443 commented on code in PR #12900:
URL: https://github.com/apache/apisix/pull/12900#discussion_r2689399374


##########
apisix/plugins/limit-count/init.lua:
##########
@@ -205,8 +205,21 @@ local function gen_limit_key(conf, ctx, key)
     -- Here we use plugin-level conf version to prevent the counter from being 
resetting
     -- because of the change elsewhere.
     -- A route which reuses a previous route's ID will inherits its counter.
-    local conf_type = ctx.conf_type_without_consumer or ctx.conf_type
-    local conf_id = ctx.conf_id_without_consumer or ctx.conf_id
+    local parent = conf._meta and conf._meta.parent
+    if not parent or not parent.resource_key or not parent.resource_version 
then
+        core.log.error("failed to generate key invalid parent: ", 
core.json.encode(parent))
+        return nil
+    end
+
+    local match, err = ngx.re.match(parent.resource_key, 
[[/apisix/([^/]+)/([^/]+)]])
+
+    if not match then
+        core.log.error("failed to generate key invalid parent resource key, 
err: ", err)
+        return nil
+    end
+
+    local conf_type = match[1]
+    local conf_id = match[2]
     local new_key = conf_type .. conf_id .. ':' .. 
apisix_plugin.conf_version(conf)

Review Comment:
   ```suggestion
       local parent = conf._meta and conf._meta.parent
   
   local new_key = parent.resource_key .. ':' .. 
apisix_plugin.conf_version(conf)
   ```



##########
apisix/plugins/limit-count/init.lua:
##########
@@ -205,8 +205,21 @@ local function gen_limit_key(conf, ctx, key)
     -- Here we use plugin-level conf version to prevent the counter from being 
resetting
     -- because of the change elsewhere.
     -- A route which reuses a previous route's ID will inherits its counter.
-    local conf_type = ctx.conf_type_without_consumer or ctx.conf_type
-    local conf_id = ctx.conf_id_without_consumer or ctx.conf_id
+    local parent = conf._meta and conf._meta.parent
+    if not parent or not parent.resource_key or not parent.resource_version 
then
+        core.log.error("failed to generate key invalid parent: ", 
core.json.encode(parent))
+        return nil
+    end
+
+    local match, err = ngx.re.match(parent.resource_key, 
[[/apisix/([^/]+)/([^/]+)]])
+
+    if not match then
+        core.log.error("failed to generate key invalid parent resource key, 
err: ", err)
+        return nil
+    end
+
+    local conf_type = match[1]
+    local conf_id = match[2]
     local new_key = conf_type .. conf_id .. ':' .. 
apisix_plugin.conf_version(conf)

Review Comment:
   ```suggestion
       local parent = conf._meta and conf._meta.parent
   
       local new_key = parent.resource_key .. ':' .. 
apisix_plugin.conf_version(conf)
   ```



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