]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Compress neural net in redis
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 10 Oct 2016 11:01:36 +0000 (12:01 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 10 Oct 2016 11:01:36 +0000 (12:01 +0100)
src/plugins/lua/fann_scores.lua

index 82b0d658c783859689544fa5588926adec313e0c..8123a92bbd71e24874122020b04cc7663f9bc80e 100644 (file)
@@ -584,8 +584,14 @@ local function maybe_load_fann(task, continue_cb, call_if_fail)
     local function redis_fann_load_cb(task, err, data)
       if not err and type(data) == 'table' and type(data[2]) == 'string' then
         local version = tonumber(data[1])
-        local ann_data = data[2]
-        local ann = rspamd_fann.load_data(ann_data)
+        local err,ann_data = rspamd_util.zstd_decompress(data[2])
+        local ann
+
+        if err or not ann_data then
+          rspamd_logger.errx(task, 'cannot decompress ann: %s', err)
+        else
+          ann = rspamd_fann.load_data(ann_data)
+        end
 
         if ann then
           current_classify_ann.loaded = true
@@ -716,7 +722,7 @@ local function save_fann(task, is_spam)
     {
       key,
       'version', tostring(current_classify_ann.version),
-      'data', tostring(data),
+      'data', rspamd_util.zstd_compress(data),
       'spam', tostring(current_classify_ann.spam_learned),
       'ham', tostring(current_classify_ann.ham_learned),
     } -- arguments