]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Add lua_util.shuffle
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 6 Aug 2021 15:35:49 +0000 (16:35 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Fri, 6 Aug 2021 15:35:49 +0000 (16:35 +0100)
lualib/lua_util.lua
lualib/rspamadm/dmarc_report.lua
src/plugins/lua/mx_check.lua

index 9dc0178398ff9c2e3dd122f9922326cc4232f37c..9294889296b543bcd4333927b6e4b89dbf103150 100644 (file)
@@ -1461,4 +1461,19 @@ exports.maybe_smtp_quote_value = function(str)
   return str
 end
 
+---[[[
+-- @function lua_util.shuffle(table)
+-- Performs in-place shuffling of a table
+-- @param {table} tbl table to shuffle
+-- @return {table} same table
+--]]]
+exports.shuffle = function(tbl)
+  local size = #tbl
+  for i = size, 1, -1 do
+    local rand = math.random(size)
+    tbl[i], tbl[rand] = tbl[rand], tbl[i]
+  end
+  return tbl
+end
+
 return exports
index 1640292481f4b578aa4633e5d688878a06276e9f..e3c59db7962c27db141c7f4773229095274c1656 100644 (file)
@@ -121,15 +121,7 @@ local function redis_prefix(...)
   return table.concat({...}, dmarc_settings.reporting.redis_keys.join_char)
 end
 
--- Helper to shuffle a Lua table
-local function shuffle(tbl)
-  local size = #tbl
-  for i = size, 1, -1 do
-    local rand = math.random(size)
-    tbl[i], tbl[rand] = tbl[rand], tbl[i]
-  end
-  return tbl
-end
+
 
 local function get_rua(rep_key)
   local parts = lua_util.str_split(rep_key, dmarc_settings.reporting.redis_keys.join_char)
@@ -605,7 +597,7 @@ local function process_report_date(opts, start_time, date)
   end
 
   -- Shuffle reports to make sending more fair
-  shuffle(reports)
+  lua_util.shuffle(reports)
   -- Remove processed key
   if not opts.no_opt then
     lua_redis.request(redis_params, redis_attrs,
index e5ac13f4e6a896495dbcd426d9741ba507609aec..e131d16d41803fa1b1d9231147dc09c040a37fea 100644 (file)
@@ -156,6 +156,7 @@ local function mx_check(task)
         mxes[name].checked = true
       else
         -- Try to open TCP connection to port 25
+
         for _,res in ipairs(results) do
           local t_ret = rspamd_tcp.new({
             task = task,