AlinsRan commented on code in PR #12029:
URL: https://github.com/apache/apisix/pull/12029#discussion_r2002543952


##########
apisix/plugins/chaitin-waf.lua:
##########
@@ -224,33 +242,37 @@ end
 
 
 local function check_match(conf, ctx)
-    local match_passed = true
+    if not conf.match or #conf.match == 0 then
+        return true
+    end
 
-    if conf.match then
-        for _, match in ipairs(conf.match) do
-            -- todo: use lrucache to cache the result
-            local exp, err = expr.new(match.vars)
-            if err then
-                local msg = "failed to create match expression for " ..
+    for _, match in ipairs(conf.match) do
+        local cache_key = core.json.encode(match.vars)

Review Comment:
   I think using the index or address(match.vars) of an array as the cache_key 
would be better.
   * ctx.conf_id .. # .. i
   * tostring(match.vars)



##########
apisix/plugins/chaitin-waf.lua:
##########
@@ -224,33 +242,37 @@ end
 
 
 local function check_match(conf, ctx)
-    local match_passed = true
+    if not conf.match or #conf.match == 0 then
+        return true
+    end
 
-    if conf.match then
-        for _, match in ipairs(conf.match) do
-            -- todo: use lrucache to cache the result
-            local exp, err = expr.new(match.vars)
-            if err then
-                local msg = "failed to create match expression for " ..
+    for _, match in ipairs(conf.match) do
+        local cache_key = core.json.encode(match.vars)
+
+        local exp, err = lrucache(cache_key, nil, function()
+            return expr.new(match.vars)
+        end)

Review Comment:
   ```suggestion
           local exp, err = lrucache(cache_key, nil, function(vars)
               return expr.new(vars)
           end, match.vars)
   ```



-- 
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: notifications-unsubscr...@apisix.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to