Browse Source

[Minor] Add lua_util.shuffle

tags/3.0
Vsevolod Stakhov 2 years ago
parent
commit
5fe80e02c8
3 changed files with 18 additions and 9 deletions
  1. 15
    0
      lualib/lua_util.lua
  2. 2
    9
      lualib/rspamadm/dmarc_report.lua
  3. 1
    0
      src/plugins/lua/mx_check.lua

+ 15
- 0
lualib/lua_util.lua View 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

+ 2
- 9
lualib/rspamadm/dmarc_report.lua View File

@@ -121,15 +121,7 @@ local function redis_prefix(...)
return table.concat({...}, dmarc_settings.reporting.redis_keys.join_char)
end

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
- 0
src/plugins/lua/mx_check.lua View 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,

Loading…
Cancel
Save