# HG changeset patch # User Matthew Wild # Date 1458132925 0 # Node ID 4454f124465a362e4b0f77ef25f4a4e454653d0f # Parent b75d29a162cd896bc82c25c222715f7b827c8532 mod_storage_memory: Support for empty username stores diff -r b75d29a162cd -r 4454f124465a mod_storage_memory/mod_storage_memory.lua --- a/mod_storage_memory/mod_storage_memory.lua Wed Mar 16 12:43:17 2016 +0000 +++ b/mod_storage_memory/mod_storage_memory.lua Wed Mar 16 12:55:25 2016 +0000 @@ -7,15 +7,17 @@ end }); +local NULL = {}; + local keyval_store = {}; keyval_store.__index = keyval_store; function keyval_store:get(username) - return self.store[username]; + return self.store[username or NULL]; end function keyval_store:set(username, data) - self.store[username] = data; + self.store[username or NULL] = data; return true; end @@ -23,17 +25,17 @@ map_store.__index = map_store; function map_store:get(username, key) - local userstore = self.store[username]; + local userstore = self.store[username or NULL]; if type(userstore) == "table" then return userstore[key]; end end function map_store:set(username, key, data) - local userstore = self.store[username]; + local userstore = self.store[username or NULL]; if userstore == nil then userstore = {}; - self.store[username] = userstore; + self.store[username or NULL] = userstore; end userstore[key] = data; return true; @@ -46,10 +48,10 @@ if type(when) ~= "number" then when, with, value = value, when, with; end - local a = self.store[username]; + local a = self.store[username or NULL]; if not a then a = {}; - self.store[username] = a; + self.store[username or NULL] = a; end local i = #a+1; local v = { key = key, when = when, with = with, value = value }; @@ -78,7 +80,7 @@ end function archive_store:find(username, query) - local a = self.store[username] or {}; + local a = self.store[username or NULL] or {}; local start, stop, step = 1, #a, 1; local qstart, qend, qwith = -math.huge, math.huge; local limit; @@ -104,16 +106,16 @@ function archive_store:delete(username, query) if not query or next(query) == nil then - self.store[username] = nil; + self.store[username or NULL] = nil; return true; end - local old = self.store[username]; + local old = self.store[username or NULL]; if not old then return true; end local qstart = query.start or -math.huge; local qend = query["end"] or math.huge; local qwith = query.with; local new = {}; - self.store[username] = new; + self.store[username or NULL] = new; local t; for i = 1, #old do i = old[i]; @@ -123,7 +125,7 @@ end end if #new == 0 then - self.store[username] = nil; + self.store[username or NULL] = nil; end return true; end