local function convert_sqlite_to_redis(redis_params,
sqlite_db_spam, sqlite_db_ham, symbol_spam, symbol_ham,
learn_cache_db, expire, reset_previous)
- local num = 0
- local total = 0
local nusers = 0
local lim = 1000 -- Update each 1000 tokens
local users_map = {}
-
+ local converted = 0
local db_spam = sqlite3.open(sqlite_db_spam)
if not db_spam then
end
-- Fill tokens, sending data to redis each `lim` records
+ local ntokens = db:query('SELECT count(*) as c FROM tokens')['c']
local tokens = {}
+ local num = 0
+ local total = 0
+
for row in db:rows('SELECT token,value,user FROM tokens;') do
local user = ''
if row.user ~= 0 and users_map[row.user] then
end
table.insert(tokens, {row.token, row.value, user})
-
num = num + 1
total = total + 1
if num > lim then
num = 0
tokens = {}
end
+
+ io.write(string.format('Processed batch: %s/%s\r', total, ntokens))
end
-- Last batch
if #tokens > 0 then
db:sql('COMMIT;')
return false
end
+
+ io.write(string.format('Processed batch: %s/%s\r', total, ntokens))
end
+ io.write('\n')
+
+ converted = converted + total
-- Close DB
db:sql('COMMIT;')
return conn:exec()
end
+ logger.messagex('Convert spam tokens')
if not convert_db(db_spam, true) then
return false
end
+ logger.messagex('Convert ham tokens')
if not convert_db(db_ham, false) then
return false
end
db:sql('COMMIT;')
if ret then
- ret,err_str = conn:exec()
+ conn:exec()
end
if ret then
- logger.messagex('Converted %d cached items from sqlite3 learned cache to redis',
+ logger.messagex('Converted %s cached items from sqlite3 learned cache to redis',
converted)
else
logger.errx('Error occurred during sending data to redis: ' .. err_str)
end
logger.messagex('Migrated %s tokens for %s users for symbols (%s, %s)',
- total, nusers, symbol_spam, symbol_ham)
+ converted, nusers, symbol_spam, symbol_ham)
return true
end
local tbl = {}
if cls.cache then
local cache = cls.cache
- if cache.type == 'sqlite3' and (cls.file or cls.path) then
- tbl.learn_cache = (cls.file or cls.path)
+ if cache.type == 'sqlite3' and (cache.file or cache.path) then
+ tbl.learn_cache = (cache.file or cache.path)
end
end