]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Fix] Do not load torch on each rspamadm invocation
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 4 Oct 2018 14:32:27 +0000 (15:32 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 4 Oct 2018 14:32:27 +0000 (15:32 +0100)
lualib/rspamadm/rescore.lua
src/plugins/lua/neural.lua

index cc331c6e85fc338192044dce5ef34bfbb555aa93..dfa73f2d5fe7f3a5df05a60f25dac73a32c61c13 100644 (file)
@@ -18,8 +18,6 @@ if not rspamd_config:has_torch() then
   return
 end
 
-local torch = require "torch"
-local nn = require "nn"
 local lua_util = require "lua_util"
 local ucl = require "ucl"
 local logger = require "rspamd_logger"
@@ -28,6 +26,10 @@ local rspamd_util = require "rspamd_util"
 local argparse = require "argparse"
 local rescore_utility = require "rescore_utility"
 
+-- Load these lazily
+local torch
+local nn
+
 local opts
 local ignore_symbols = {
   ['DATE_IN_PAST'] =true,
@@ -509,6 +511,8 @@ local function get_threshold()
 end
 
 local function handler(args)
+  torch = require "torch"
+  nn = require "nn"
   opts = parser:parse(args)
   if not opts['log'] then
     parser:error('no log specified')
index 9d0bbb446867acbcbe8897710517196f69b94e97..022160083260de26fd56a0e8ae7ced43c5ef9516 100644 (file)
@@ -33,8 +33,6 @@ local N = "neural"
 
 if rspamd_config:has_torch() then
   use_torch = true
-  torch = require "torch"
-  nn = require "nn"
 end
 
 -- Module vars
@@ -949,6 +947,9 @@ else
 
   if opts.disable_torch then
     use_torch = false
+  else
+    torch = require "torch"
+    nn = require "nn"
   end
 
   local id = rspamd_config:register_symbol({
@@ -1017,9 +1018,9 @@ else
       if worker:is_primary_controller() then
         -- We also want to train neural nets when they have enough data
         rspamd_config:add_periodic(ev_base, 0.0,
-          function(_, _)
-            return maybe_train_anns(rule, cfg, ev_base, worker)
-          end)
+            function(_, _)
+              return maybe_train_anns(rule, cfg, ev_base, worker)
+            end)
       end
     end)
   end