Browse Source

[Minor] Remove special handling

tags/3.8.0
Vsevolod Stakhov 5 months ago
parent
commit
a00c667b4c
No account linked to committer's email address
2 changed files with 2 additions and 5 deletions
  1. 1
    3
      lualib/lua_bayes_redis.lua
  2. 1
    2
      lualib/redis_scripts/bayes_cache_learn.lua

+ 1
- 3
lualib/lua_bayes_redis.lua View File

local function gen_cache_learn_functor(redis_params, learn_script_id, conf) local function gen_cache_learn_functor(redis_params, learn_script_id, conf)
local packed_conf = ucl.to_format(conf, 'msgpack') local packed_conf = ucl.to_format(conf, 'msgpack')
return function(task, cache_id, is_spam) return function(task, cache_id, is_spam)
local is_per_user = task:get_mempool():has_variable('stat_user')
local function learn_redis_cb(err, data) local function learn_redis_cb(err, data)
lua_util.debugm(N, task, 'learn_cache redis cb: %s, %s', err, data) lua_util.debugm(N, task, 'learn_cache redis cb: %s, %s', err, data)
end end
lua_redis.exec_redis_script(learn_script_id, lua_redis.exec_redis_script(learn_script_id,
{ task = task, is_write = true, key = cache_id }, { task = task, is_write = true, key = cache_id },
learn_redis_cb, learn_redis_cb,
{ cache_id, is_spam and "1" or "0", packed_conf, is_per_user and "1" or "0" })
{ cache_id, is_spam and "1" or "0", packed_conf })


end end
end end
cache_prefix = "learned_ids", cache_prefix = "learned_ids",
cache_max_elt = 10000, -- Maximum number of elements in the cache key cache_max_elt = 10000, -- Maximum number of elements in the cache key
cache_max_keys = 5, -- Maximum number of keys in the cache cache_max_keys = 5, -- Maximum number of keys in the cache
cache_per_user_mult = 0.1, -- Multiplier for per user cache size
cache_elt_len = 32, -- Length of the element in the cache (will trim id to that value) cache_elt_len = 32, -- Length of the element in the cache (will trim id to that value)
} }



+ 1
- 2
lualib/redis_scripts/bayes_cache_learn.lua View File

-- key1 - cache id -- key1 - cache id
-- key3 - is spam (1 or 0) -- key3 - is spam (1 or 0)
-- key3 - configuration table in message pack -- key3 - configuration table in message pack


local cache_id = KEYS[1] local cache_id = KEYS[1]
local is_spam = KEYS[2] local is_spam = KEYS[2]
local conf = cmsgpack.unpack(KEYS[3]) local conf = cmsgpack.unpack(KEYS[3])
local is_per_user = KEYS[4] == "1"
cache_id = string.sub(cache_id, 1, conf.cache_elt_len) cache_id = string.sub(cache_id, 1, conf.cache_elt_len)


-- Try each prefix that is in Redis (as some other instance might have set it) -- Try each prefix that is in Redis (as some other instance might have set it)
end end


local added = false local added = false
local lim = is_per_user and conf.cache_max_elt * conf.cache_per_user_mult or conf.cache_max_elt
local lim = conf.cache_max_elt
for i = 0, conf.cache_max_keys do for i = 0, conf.cache_max_keys do
if not added then if not added then
local prefix = conf.cache_prefix .. string.rep("X", i) local prefix = conf.cache_prefix .. string.rep("X", i)

Loading…
Cancel
Save