Update colddb.lua

This commit is contained in:
Coder12a 2018-12-08 14:56:38 -06:00
parent b9a64f723c
commit 60bc174189

View File

@ -213,8 +213,13 @@ local function delete_lines_func_end(args)
args.file:seek("set") args.file:seek("set")
args.file:write(string.format("%i",args.count)) args.file:write(string.format("%i",args.count))
args.file:close() args.file:close()
if args.count < 1 then
os.remove(args.oldfile)
os.remove(args.copyfile)
else
os.remove(args.oldfile) os.remove(args.oldfile)
os.rename(args.copyfile, args.oldfile) os.rename(args.copyfile, args.oldfile)
end
for i,l in pairs(args.removedlist) do for i,l in pairs(args.removedlist) do
db.indexes_pool[cs].deleted_items[i] = nil db.indexes_pool[cs].deleted_items[i] = nil
end end
@ -440,10 +445,6 @@ function colddb.iterate_index_table(db,begin_func,func_on_iterate,end_func,args,
-- Get count -- Get count
fl:seek("set") fl:seek("set")
local c = tonumber(fl:read("*l")) local c = tonumber(fl:read("*l"))
if c < 1 then
-- If theres nothing to index then return
return false
end
if not args then if not args then
args = {} args = {}
end end
@ -455,6 +456,12 @@ function colddb.iterate_index_table(db,begin_func,func_on_iterate,end_func,args,
args = a args = a
end end
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 -- Start iterating the index table
iterate(db,func_on_iterate,end_func,c,cs,args) iterate(db,func_on_iterate,end_func,c,cs,args)
elseif f and f.file then elseif f and f.file then
@ -537,6 +544,7 @@ function colddb.set_key(db,name,tag_name)
end end
function colddb.get(db,name,tag_name,callback) function colddb.get(db,name,tag_name,callback)
if callback then
extended_api.Async.queue_task(db.async_pool,function() extended_api.Async.queue_task(db.async_pool,function()
local t = "" local t = ""
if tag_name then if tag_name then
@ -555,9 +563,28 @@ function colddb.get(db,name,tag_name,callback)
end end
return nil return nil
end,callback) end,callback)
else
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
end end
function colddb.get_key(db,name,tag_name,callback) function colddb.get_key(db,name,tag_name,callback)
if callback then
extended_api.Async.queue_task(db.async_pool,function() extended_api.Async.queue_task(db.async_pool,function()
local t = "" local t = ""
if tag_name then if tag_name then
@ -576,6 +603,24 @@ function colddb.get_key(db,name,tag_name,callback)
end end
return nil return nil
end,callback) end,callback)
else
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
end end
function colddb.remove(db,name,tag_name) function colddb.remove(db,name,tag_name)