Browse Source

[Minor] Add lua_util.shuffle

pull/3844/head
Vsevolod Stakhov 4 years ago
parent
commit
5fe80e02c8
  1. 15
      lualib/lua_util.lua
  2. 12
      lualib/rspamadm/dmarc_report.lua
  3. 1
      src/plugins/lua/mx_check.lua

15
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

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

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

Loading…
Cancel
Save