spacewander commented on code in PR #8820:
URL: https://github.com/apache/apisix/pull/8820#discussion_r1109404784


##########
apisix/admin/resource.lua:
##########
@@ -31,27 +31,32 @@ local mt = {
 }
 
 
+local no_id_res = {"consumers", "plugin_metadata"}
+
+
 function _M:check_conf(id, conf, need_id)
     -- check if missing configurations
     if not conf then
         return nil, {error_msg = "missing configurations"}
     end
 
     -- check id if need id
-    id = id or conf.id
-    if need_id and not id then
-        return nil, {error_msg = "missing ".. self.kind .. " id"}
-    end
+    if not core.table.array_find(no_id_res, self.name) then
+        id = id or conf.id
+        if need_id and not id then
+            return nil, {error_msg = "missing ".. self.kind .. " id"}
+        end
 
-    if not need_id and id then
-        return nil, {error_msg = "wrong ".. self.kind .. " id, do not need it"}
-    end
+        if not need_id and id then
+            return nil, {error_msg = "wrong ".. self.kind .. " id, do not need 
it"}
+        end
 
-    if need_id and conf.id and tostring(conf.id) ~= tostring(id) then
-        return nil, {error_msg = "wrong ".. self.kind .. " id"}
-    end
+        if need_id and conf.id and tostring(conf.id) ~= tostring(id) then
+            return nil, {error_msg = "wrong ".. self.kind .. " id"}
+        end
 
-    conf.id = id
+        conf.id = id
+    end
 
     core.log.info("schema: ", core.json.delay_encode(self.schema))

Review Comment:
   Look like in these resources, there is some redundant code? For example, the 
scheme will be logged twice.



##########
apisix/admin/resource.lua:
##########
@@ -31,27 +31,32 @@ local mt = {
 }
 
 
+local no_id_res = {"consumers", "plugin_metadata"}

Review Comment:
   We can define it as hash to speed up the lookup?



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