]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Don't load torch unless really needed
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 6 Oct 2018 08:26:18 +0000 (09:26 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 6 Oct 2018 08:26:18 +0000 (09:26 +0100)
lualib/lua_nn.lua
rules/rspamd.lua

index d0d2d5265d8f6bd0ece43b40faa40de61d7cbe0c..d16f0a768fdd361305e341ce8c3f0442869449d5 100644 (file)
@@ -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
index 67136cc6e71f4b402fd357785f70a274cf6e0ef2..646dc5afd44412b9e6a54790e9578142f3d60410 100644 (file)
@@ -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