Small code style changes
This commit is contained in:
parent
647330a033
commit
69f789e5fd
39
colddb.lua
39
colddb.lua
|
@ -13,7 +13,6 @@ function colddb.Colddb(directory)
|
||||||
local self = {}
|
local self = {}
|
||||||
|
|
||||||
self.db = {
|
self.db = {
|
||||||
global_tag = "",
|
|
||||||
directory = directory,
|
directory = directory,
|
||||||
tags = {},
|
tags = {},
|
||||||
mem_pool = {},
|
mem_pool = {},
|
||||||
|
@ -70,9 +69,10 @@ function colddb.Colddb(directory)
|
||||||
|
|
||||||
local function delete_lines_func_end(args)
|
local function delete_lines_func_end(args)
|
||||||
local cs = args.cs
|
local cs = args.cs
|
||||||
if self.db.indexes_pool[cs] or self.db.indexes_pool[cs].file then
|
local index = self.db.indexes_pool[cs]
|
||||||
self.db.indexes_pool[cs].file:close()
|
if index and index.file then
|
||||||
self.db.indexes_pool[cs].file = nil
|
index.file:close()
|
||||||
|
index.file = nil
|
||||||
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()
|
||||||
|
@ -83,10 +83,12 @@ function colddb.Colddb(directory)
|
||||||
os.remove(args.oldfile)
|
os.remove(args.oldfile)
|
||||||
os.rename(args.copyfile, args.oldfile)
|
os.rename(args.copyfile, args.oldfile)
|
||||||
end
|
end
|
||||||
|
local pool = self.db.indexes_pool[cs]
|
||||||
for i, l in pairs(args.removedlist) do
|
for i, l in pairs(args.removedlist) do
|
||||||
self.db.indexes_pool[cs].deleted_items[i] = nil
|
pool.deleted_items[i] = nil
|
||||||
end
|
end
|
||||||
self.db.indexes_pool[cs].deleting = false
|
pool.deleting = false
|
||||||
|
self.db.indexes_pool[cs] = pool
|
||||||
end
|
end
|
||||||
args = nil
|
args = nil
|
||||||
end
|
end
|
||||||
|
@ -96,7 +98,7 @@ function colddb.Colddb(directory)
|
||||||
local fl = f.file
|
local fl = f.file
|
||||||
self.db.async.iterate(1, count, function(i)
|
self.db.async.iterate(1, count, function(i)
|
||||||
local line = fl:read("*l")
|
local line = fl:read("*l")
|
||||||
if args.do_not_skip_removed_items or not self.db.indexes_pool[cs].deleted_items[line] then
|
if args.do_not_skip_removed_items or not f.deleted_items[line] then
|
||||||
local ar = func_on_iterate(line, i, args)
|
local ar = func_on_iterate(line, i, args)
|
||||||
if ar ~= nil then
|
if ar ~= nil then
|
||||||
args = ar
|
args = ar
|
||||||
|
@ -107,8 +109,9 @@ function colddb.Colddb(directory)
|
||||||
if end_func then
|
if end_func then
|
||||||
end_func(args)
|
end_func(args)
|
||||||
end
|
end
|
||||||
if self.db.iterate_queue[cs] and self.db.iterate_queue[cs][1] then
|
local iterate_queue = self.db.iterate_queue[cs]
|
||||||
local copy = self.db.iterate_queue[cs][1]
|
if iterate_queue and iterate_queue[1] then
|
||||||
|
local copy = iterate_queue[1]
|
||||||
f = self.db.indexes_pool[cs]
|
f = self.db.indexes_pool[cs]
|
||||||
if not f or not f.file then
|
if not f or not f.file then
|
||||||
self.open_index_table(copy.tag_name)
|
self.open_index_table(copy.tag_name)
|
||||||
|
@ -139,12 +142,14 @@ function colddb.Colddb(directory)
|
||||||
t = self.get_tag(tag_name)
|
t = self.get_tag(tag_name)
|
||||||
end
|
end
|
||||||
local cs = string.format("%s%s", t, name)
|
local cs = string.format("%s%s", t, name)
|
||||||
if not self.db.mem_pool[cs] then
|
local mem_pool = self.db.mem_pool[cs]
|
||||||
self.db.mem_pool[cs] = {mem = _table, indexes = self.db.indexes}
|
if not mem_pool then
|
||||||
|
mem_pool = {mem = _table, indexes = self.db.indexes}
|
||||||
else
|
else
|
||||||
self.db.mem_pool[cs].mem = _table
|
mem_pool.mem = _table
|
||||||
self.db.mem_pool[cs].indexes = self.db.indexes
|
mem_pool.indexes = self.db.indexes
|
||||||
end
|
end
|
||||||
|
self.db.mem_pool[cs] = mem_pool
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -324,12 +329,12 @@ function colddb.Colddb(directory)
|
||||||
f.deleted_items[i] = true
|
f.deleted_items[i] = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not self.db.indexes_pool[cs].deleting then
|
if not f.deleting then
|
||||||
self.db.indexes_pool[cs].deleting = false
|
self.db.indexes_pool[cs].deleting = false
|
||||||
end
|
end
|
||||||
if f and f.file and not self.db.indexes_pool[cs].deleting then
|
if f and f.file and not f.deleting then
|
||||||
self.db.indexes_pool[cs].deleting = true
|
self.db.indexes_pool[cs].deleting = true
|
||||||
if self.db.indexes_pool[cs].needs_flushing == true then
|
if f.needs_flushing == true then
|
||||||
f.file:flush()
|
f.file:flush()
|
||||||
self.db.indexes_pool[cs].needs_flushing = false
|
self.db.indexes_pool[cs].needs_flushing = false
|
||||||
end
|
end
|
||||||
|
@ -649,7 +654,7 @@ function colddb.Colddb(directory)
|
||||||
self.db.mem_pool_del[cs] = true
|
self.db.mem_pool_del[cs] = true
|
||||||
if self.db.indexes and self.file_Exists("æIndex_table", tag_name) then
|
if self.db.indexes and self.file_Exists("æIndex_table", tag_name) then
|
||||||
self.db.async.queue_task(function()
|
self.db.async.queue_task(function()
|
||||||
local cs2 = string.format("%s%s",t,"æIndex_table")
|
local cs2 = string.format("%s%s", t, "æIndex_table")
|
||||||
if not (self.db.indexes_pool[cs2] and self.db.indexes_pool[cs2].file) then
|
if not (self.db.indexes_pool[cs2] and self.db.indexes_pool[cs2].file) then
|
||||||
self.open_index_table(tag_name)
|
self.open_index_table(tag_name)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user