From 33f1f5411b4ce38b2d2a61741b6e16aba92a90e5 Mon Sep 17 00:00:00 2001 From: Coder12a <38924418+Coder12a@users.noreply.github.com> Date: Sat, 2 Feb 2019 18:28:55 -0600 Subject: [PATCH] set and save: Memory --- colddb.lua | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/colddb.lua b/colddb.lua index a27fae5..03514c9 100644 --- a/colddb.lua +++ b/colddb.lua @@ -361,7 +361,7 @@ function colddb.Colddb(dir) return nil end - self.append_entry_file = function(name, key, tag_name) + self.append_entry_file = function(name, key, op, tag_name) local t = "" if tag_name then t = self.get_tag(tag_name) @@ -392,10 +392,18 @@ function colddb.Colddb(dir) end indexes_pool[cs].needs_flushing = true local c = 0 - for i in pairs(key) do - fl:seek("end") - fl:write(string.format("\n%s", i)) - c = c + 1 + if op and op == "key" then + for i in pairs(key) do + fl:seek("end") + fl:write(string.format("\n%s", i)) + c = c + 1 + end + elseif not op or op == "value" then + for i, j in pairs(key) do + fl:seek("end") + fl:write(string.format("\n%s", j)) + c = c + 1 + end end fl:seek("set") local count = tonumber(fl:read("*l")) @@ -489,6 +497,34 @@ function colddb.Colddb(dir) table.insert(iterate_queue[cs], _table) end end + + self.set_mem = function(name, _table, tag_name) + local t = "" + if tag_name then + t = self.get_tag(tag_name) + end + load_into_mem(name, _table, tag_name) + local cs = string.format("%s%s", t, name) + mem_pool_del[cs] = nil + end + + self.save_mem = function(name, tag_name) + local t = "" + + if tag_name then + t = self.get_tag(tag_name) + end + + local cs = string.format("%s%s", t, name) + + async.queue_task(function() + if mem_pool[cs] ~= nil then + save_table(name, mem_pool[cs].mem, tag_name) + end + end) + + mem_pool_del[cs] = nil + end self.set = function(name, _table, tag_name) local t = ""