commit 5fe80e0: [Minor] Add lua_util.shuffle
Vsevolod Stakhov
vsevolod at highsecure.ru
Fri Aug 6 15:42:06 UTC 2021
Author: Vsevolod Stakhov
Date: 2021-08-06 16:35:49 +0100
URL: https://github.com/rspamd/rspamd/commit/5fe80e02c8e13ff5d556eb4801087166103ae4a1
[Minor] Add lua_util.shuffle
---
lualib/lua_util.lua | 15 +++++++++++++++
lualib/rspamadm/dmarc_report.lua | 12 ++----------
src/plugins/lua/mx_check.lua | 1 +
3 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua
index 9dc017839..929488929 100644
--- a/lualib/lua_util.lua
+++ b/lualib/lua_util.lua
@@ -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
diff --git a/lualib/rspamadm/dmarc_report.lua b/lualib/rspamadm/dmarc_report.lua
index 164029248..e3c59db79 100644
--- a/lualib/rspamadm/dmarc_report.lua
+++ b/lualib/rspamadm/dmarc_report.lua
@@ -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,
diff --git a/src/plugins/lua/mx_check.lua b/src/plugins/lua/mx_check.lua
index e5ac13f4e..e131d16d4 100644
--- a/src/plugins/lua/mx_check.lua
+++ b/src/plugins/lua/mx_check.lua
@@ -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,
More information about the Commits
mailing list