working on new history code
This commit is contained in:
+2
-55
@@ -8,9 +8,6 @@ aux_database = {}
|
||||
function public.on_load()
|
||||
private.perform_migration(aux_database)
|
||||
aux_database.version = DATABASE_VERSION
|
||||
Aux.control.as_soon_as(function() return UnitFactionGroup('player') end, function()
|
||||
public.load_snapshot().compact()
|
||||
end)
|
||||
end
|
||||
|
||||
function private.perform_migration()
|
||||
@@ -29,13 +26,6 @@ function public.load_dataset()
|
||||
return aux_database[dataset_key]
|
||||
end
|
||||
|
||||
function public.load_snapshot()
|
||||
local dataset = public.load_dataset()
|
||||
dataset.snapshot = dataset.snapshot or {}
|
||||
local snapshot = private.snapshot(dataset.snapshot)
|
||||
return snapshot
|
||||
end
|
||||
|
||||
function public.serialize(data, separator, compactor)
|
||||
local data_string = ''
|
||||
local i = 1
|
||||
@@ -53,7 +43,7 @@ function public.serialize(data, separator, compactor)
|
||||
end
|
||||
|
||||
function public.deserialize(data_string, separator, compactor)
|
||||
if data_string == '' then
|
||||
if not data_string or data_string == '' then
|
||||
return {}
|
||||
end
|
||||
|
||||
@@ -82,47 +72,4 @@ function public.deserialize(data_string, separator, compactor)
|
||||
return data
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function private.snapshot(data)
|
||||
local self = {}
|
||||
|
||||
function self.add(signature, duration)
|
||||
local HOUR = 60 * 60 * 60
|
||||
local seconds
|
||||
if duration == 1 then
|
||||
seconds = HOUR / 2
|
||||
elseif duration == 2 then
|
||||
seconds = HOUR * 2
|
||||
elseif duration == 3 then
|
||||
seconds = HOUR * 8
|
||||
elseif duration == 4 then
|
||||
seconds = HOUR * 24
|
||||
end
|
||||
data[signature] = time() + seconds
|
||||
end
|
||||
|
||||
function self.contains(signature)
|
||||
return data[signature] ~= nil and data[signature] >= time()
|
||||
end
|
||||
|
||||
function self.compact()
|
||||
for signature, expiration in pairs(data) do
|
||||
if expiration < time() then
|
||||
data[signature] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function self.signatures()
|
||||
local signatures = {}
|
||||
for signature, _ in pairs(data) do
|
||||
if data[signature] >= time() then
|
||||
tinsert(signatures, signature)
|
||||
end
|
||||
end
|
||||
return signatures
|
||||
end
|
||||
|
||||
return self
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user