diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2022-06-20 20:46:27 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2022-06-20 20:46:27 +0100 |
commit | 3a8bb197fb08ef3832e45f7ee270cc66bc6ea224 (patch) | |
tree | 9c7bf5337990d5124a8b48f3dadaae539738d5ef /lualib/plugins/neural.lua | |
parent | 4a1c5901671b763efa1a11e28a95d1b95152de70 (diff) | |
download | rspamd-3a8bb197fb08ef3832e45f7ee270cc66bc6ea224.tar.gz rspamd-3a8bb197fb08ef3832e45f7ee270cc66bc6ea224.zip |
[Minor] Add some sanity checks to the redis scripts
Diffstat (limited to 'lualib/plugins/neural.lua')
-rw-r--r-- | lualib/plugins/neural.lua | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/lualib/plugins/neural.lua b/lualib/plugins/neural.lua index d2db2f519..67051fa1a 100644 --- a/lualib/plugins/neural.lua +++ b/lualib/plugins/neural.lua @@ -127,12 +127,16 @@ local redis_lua_script_maybe_invalidate = [[ local lim = tonumber(KEYS[2]) if card > lim then local to_delete = redis.call('ZRANGE', KEYS[1], 0, card - lim - 1) - for _,k in ipairs(to_delete) do - local tb = cjson.decode(k) - redis.call('DEL', tb.redis_key) - -- Also train vectors - redis.call('DEL', tb.redis_key .. '_spam') - redis.call('DEL', tb.redis_key .. '_ham') + if to_delete then + for _,k in ipairs(to_delete) do + local tb = cjson.decode(k) + if type(tb) == 'table' and type(tb.redis_key) == 'string' then + redis.call('DEL', tb.redis_key) + -- Also train vectors + redis.call('DEL', tb.redis_key .. '_spam') + redis.call('DEL', tb.redis_key .. '_ham') + end + end end redis.call('ZREMRANGEBYRANK', KEYS[1], 0, card - lim - 1) return to_delete |