Update colddb.lua
This commit is contained in:
parent
b9a64f723c
commit
60bc174189
65
colddb.lua
65
colddb.lua
|
@ -213,8 +213,13 @@ local function delete_lines_func_end(args)
|
|||
args.file:seek("set")
|
||||
args.file:write(string.format("%i",args.count))
|
||||
args.file:close()
|
||||
os.remove(args.oldfile)
|
||||
os.rename(args.copyfile, args.oldfile)
|
||||
if args.count < 1 then
|
||||
os.remove(args.oldfile)
|
||||
os.remove(args.copyfile)
|
||||
else
|
||||
os.remove(args.oldfile)
|
||||
os.rename(args.copyfile, args.oldfile)
|
||||
end
|
||||
for i,l in pairs(args.removedlist) do
|
||||
db.indexes_pool[cs].deleted_items[i] = nil
|
||||
end
|
||||
|
@ -440,10 +445,6 @@ function colddb.iterate_index_table(db,begin_func,func_on_iterate,end_func,args,
|
|||
-- Get count
|
||||
fl:seek("set")
|
||||
local c = tonumber(fl:read("*l"))
|
||||
if c < 1 then
|
||||
-- If theres nothing to index then return
|
||||
return false
|
||||
end
|
||||
if not args then
|
||||
args = {}
|
||||
end
|
||||
|
@ -455,6 +456,12 @@ function colddb.iterate_index_table(db,begin_func,func_on_iterate,end_func,args,
|
|||
args = a
|
||||
end
|
||||
end
|
||||
if c < 1 then
|
||||
-- If theres nothing to index then return
|
||||
end_func(args)
|
||||
db.indexes_pool[cs].iterating = false
|
||||
return false
|
||||
end
|
||||
-- Start iterating the index table
|
||||
iterate(db,func_on_iterate,end_func,c,cs,args)
|
||||
elseif f and f.file then
|
||||
|
@ -537,7 +544,26 @@ function colddb.set_key(db,name,tag_name)
|
|||
end
|
||||
|
||||
function colddb.get(db,name,tag_name,callback)
|
||||
extended_api.Async.queue_task(db.async_pool,function()
|
||||
if callback then
|
||||
extended_api.Async.queue_task(db.async_pool,function()
|
||||
local t = ""
|
||||
if tag_name then
|
||||
t = colddb.get_tag(db,tag_name)
|
||||
end
|
||||
local cs = string.format("%s%s",t,name)
|
||||
local pm = db.mem_pool[cs]
|
||||
if pm then
|
||||
return pm.mem
|
||||
else
|
||||
local _table = colddb.load_table(db,name,tag_name)
|
||||
if _table then
|
||||
load_into_mem(db,name,_table,tag_name)
|
||||
return _table
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end,callback)
|
||||
else
|
||||
local t = ""
|
||||
if tag_name then
|
||||
t = colddb.get_tag(db,tag_name)
|
||||
|
@ -554,11 +580,30 @@ function colddb.get(db,name,tag_name,callback)
|
|||
end
|
||||
end
|
||||
return nil
|
||||
end,callback)
|
||||
end
|
||||
end
|
||||
|
||||
function colddb.get_key(db,name,tag_name,callback)
|
||||
extended_api.Async.queue_task(db.async_pool,function()
|
||||
if callback then
|
||||
extended_api.Async.queue_task(db.async_pool,function()
|
||||
local t = ""
|
||||
if tag_name then
|
||||
t = colddb.get_tag(db,tag_name)
|
||||
end
|
||||
local cs = string.format("%s%s",t,name)
|
||||
local pm = db.mem_pool[cs]
|
||||
if pm then
|
||||
return true
|
||||
else
|
||||
local bool = colddb.load_key(db,name,tag_name)
|
||||
if bool then
|
||||
load_into_mem(db,name,bool,tag_name)
|
||||
return bool
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end,callback)
|
||||
else
|
||||
local t = ""
|
||||
if tag_name then
|
||||
t = colddb.get_tag(db,tag_name)
|
||||
|
@ -575,7 +620,7 @@ function colddb.get_key(db,name,tag_name,callback)
|
|||
end
|
||||
end
|
||||
return nil
|
||||
end,callback)
|
||||
end
|
||||
end
|
||||
|
||||
function colddb.remove(db,name,tag_name)
|
||||
|
|
Loading…
Reference in New Issue
Block a user