spacewander commented on a change in pull request #5331:
URL: https://github.com/apache/apisix/pull/5331#discussion_r736188923



##########
File path: apisix/plugins/grpc-transcode/proto.lua
##########
@@ -63,14 +70,23 @@ local function create_proto_obj(proto_id)
         return nil, "failed to find proto by id: " .. proto_id
     end
 
-    return compile_proto(content)
-end
+    local compiled, res = compile_proto(content)
+
+    if compiled == nil then
+        return nil, res
+    end
 
+    local cache = {}

Review comment:
       `index` is a more appreciated name

##########
File path: apisix/plugins/grpc-transcode/proto.lua
##########
@@ -63,14 +70,23 @@ local function create_proto_obj(proto_id)
         return nil, "failed to find proto by id: " .. proto_id
     end
 
-    return compile_proto(content)
-end
+    local compiled, res = compile_proto(content)
+
+    if compiled == nil then

Review comment:
       ```suggestion
       if not compiled then
   ```
   is more common style

##########
File path: apisix/plugins/grpc-transcode/util.lua
##########
@@ -14,37 +14,26 @@
 -- See the License for the specific language governing permissions and
 -- limitations under the License.
 --
-local core     = require("apisix.core")
-local json     = core.json
-local pb       = require("pb")
-local ngx      = ngx
-local pairs    = pairs
-local ipairs   = ipairs
-local string   = string
-local tonumber = tonumber
-local type     = type
+local core              = require("apisix.core")
+local proto_fake_file   = 
require("apisix..plugins.grpc-transcode.proto").proto_fake_file

Review comment:
       ```suggestion
   local proto_fake_file   = 
require("apisix.plugins.grpc-transcode.proto").proto_fake_file
   ```

##########
File path: apisix/plugins/grpc-transcode/util.lua
##########
@@ -14,37 +14,26 @@
 -- See the License for the specific language governing permissions and
 -- limitations under the License.
 --
-local core     = require("apisix.core")
-local json     = core.json
-local pb       = require("pb")
-local ngx      = ngx
-local pairs    = pairs
-local ipairs   = ipairs
-local string   = string
-local tonumber = tonumber
-local type     = type
+local core              = require("apisix.core")
+local proto_fake_file   = 
require("apisix..plugins.grpc-transcode.proto").proto_fake_file
+local json              = core.json
+local pb                = require("pb")
+local ngx               = ngx
+local string            = string
+local tonumber          = tonumber
+local type              = type
 
 
 local _M = {version = 0.1}
 
 
 function _M.find_method(protos, service, method)
-    for k, loaded in pairs(protos) do
-        if type(loaded) == 'table' then
-            local package = loaded.package
-            for _, s in ipairs(loaded.service or {}) do
-                if package .. "." .. s.name == service then
-                    for _, m in ipairs(s.method) do
-                        if m.name == method then
-                            return m
-                        end
-                    end
-                end
-            end
-        end
+    local loaded = protos[proto_fake_file]
+    if loaded == nil or type(loaded) ~= "table" then
+        return nil
     end
 
-    return nil
+    return loaded.cache[service .. '.' .. method]

Review comment:
       I think a package.service + method is better, so we don't need to create 
package.service.method temporary string

##########
File path: apisix/plugins/grpc-transcode/proto.lua
##########
@@ -63,14 +70,23 @@ local function create_proto_obj(proto_id)
         return nil, "failed to find proto by id: " .. proto_id
     end
 
-    return compile_proto(content)
-end
+    local compiled, res = compile_proto(content)

Review comment:
       ```suggestion
       local compiled, err = compile_proto(content)
   ```
   
   The second returned value is err msg.




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