summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-10-06 09:26:18 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-10-06 09:26:18 +0100
commit9a3b5ef566ad7c57b6509511e53f9dbe58340268 (patch)
treeb3b610c4d7ac1ac0de96fa089977f19225c09934
parentdae0ccff831a4a9a2fa536cc4da348bb764a4645 (diff)
downloadrspamd-9a3b5ef566ad7c57b6509511e53f9dbe58340268.tar.gz
rspamd-9a3b5ef566ad7c57b6509511e53f9dbe58340268.zip
[Minor] Don't load torch unless really needed
-rw-r--r--lualib/lua_nn.lua15
-rw-r--r--rules/rspamd.lua2
2 files changed, 10 insertions, 7 deletions
diff --git a/lualib/lua_nn.lua b/lualib/lua_nn.lua
index d0d2d5265..d16f0a768 100644
--- a/lualib/lua_nn.lua
+++ b/lualib/lua_nn.lua
@@ -20,9 +20,13 @@ local exports = {}
local lua_nn_models = {}
-if rspamd_config:has_torch() then
- torch = require "torch"
- torch.setnumthreads(1)
+local conf_section = rspamd_config:get_all_opt("nn_models")
+
+if conf_section then
+ if rspamd_config:has_torch() then
+ torch = require "torch"
+ torch.setnumthreads(1)
+ end
end
if torch then
@@ -43,10 +47,9 @@ if torch then
end
end
end
- local section = rspamd_config:get_all_opt("nn_models")
- if section and type(section) == 'table' then
- for k,v in pairs(section) do
+ if conf_section and type(conf_section) == 'table' then
+ for k,v in pairs(conf_section) do
if not rspamd_config:add_map(v, "nn map " .. k, gen_process_callback(k)) then
rspamd_logger.warnx(rspamd_config, 'cannot load NN map %1', k)
end
diff --git a/rules/rspamd.lua b/rules/rspamd.lua
index 67136cc6e..646dc5afd 100644
--- a/rules/rspamd.lua
+++ b/rules/rspamd.lua
@@ -65,4 +65,4 @@ if rmaps and type(rmaps) == 'table' then
end
local rspamd_nn = require "lua_nn"
-rspamd_nn.load_rspamd_nn() -- Load defined models \ No newline at end of file
+rspamd_nn.load_rspamd_nn() -- Load defined models if any \ No newline at end of file