comparison mod_storage_gdbm/mod_storage_gdbm.lua @ 1653:1fe899527ee5

mod_storage_gdbm: Cleanup [luacheck]
author Kim Alvefur <zash@zash.se>
date Tue, 07 Apr 2015 17:35:37 +0200
parents b877b75eb973
children 54c8a0cb2996
comparison
equal deleted inserted replaced
1652:9a3d2f1479a4 1653:1fe899527ee5
3 -- 3 --
4 -- This file is MIT/X11 licensed. 4 -- This file is MIT/X11 licensed.
5 -- 5 --
6 -- Depends on lgdbm: 6 -- Depends on lgdbm:
7 -- http://webserver2.tecgraf.puc-rio.br/~lhf/ftp/lua/#lgdbm 7 -- http://webserver2.tecgraf.puc-rio.br/~lhf/ftp/lua/#lgdbm
8 --
9 -- luacheck: globals open purge
8 10
9 local gdbm = require"gdbm"; 11 local gdbm = require"gdbm";
10 local path = require"util.paths"; 12 local path = require"util.paths";
11 local lfs = require"lfs"; 13 local lfs = require"lfs";
12 local st = require"util.stanza"; 14 local st = require"util.stanza";
16 local serialize = serialization.serialize; 18 local serialize = serialization.serialize;
17 local deserialize = serialization.deserialize; 19 local deserialize = serialization.deserialize;
18 20
19 local g_set, g_get, g_del = gdbm.replace, gdbm.fetch, gdbm.delete; 21 local g_set, g_get, g_del = gdbm.replace, gdbm.fetch, gdbm.delete;
20 local g_first, g_next = gdbm.firstkey, gdbm.nextkey; 22 local g_first, g_next = gdbm.firstkey, gdbm.nextkey;
21
22 local t_remove = table.remove;
23 23
24 local empty = {}; 24 local empty = {};
25 25
26 local function id(v) return v; end 26 local function id(v) return v; end
27 27
92 ok, err = self:set(username, meta); 92 ok, err = self:set(username, meta);
93 if not ok then return nil, err; end 93 if not ok then return nil, err; end
94 return key; 94 return key;
95 end 95 end
96 96
97 local deserialize = { 97 local deserialize_map = {
98 stanza = st.deserialize; 98 stanza = st.deserialize;
99 }; 99 };
100 100
101 function archive:find(username, query) 101 function archive:find(username, query)
102 query = query or empty; 102 query = query or empty;
121 if (not query.with or item.with == query.with) 121 if (not query.with or item.with == query.with)
122 and (not query.start or item.when >= query.start) 122 and (not query.start or item.when >= query.start)
123 and (not query["end"] or item.when <= query["end"]) then 123 and (not query["end"] or item.when <= query["end"]) then
124 s = i + d; c = c + 1; 124 s = i + d; c = c + 1;
125 value = self:get(prefix..item.key); 125 value = self:get(prefix..item.key);
126 return item.key, (deserialize[item.type] or id)(value), item.when, item.with; 126 return item.key, (deserialize_map[item.type] or id)(value), item.when, item.with;
127 end 127 end
128 end 128 end
129 end 129 end
130 end 130 end
131 131
162 end 162 end
163 return true; 163 return true;
164 end 164 end
165 165
166 function module.unload() 166 function module.unload()
167 for path, db in pairs(cache) do 167 for db_path, db in pairs(cache) do
168 module:log("debug", "Closing db at %q", db_path);
168 gdbm.sync(db); 169 gdbm.sync(db);
169 gdbm.close(db); 170 gdbm.close(db);
170 end 171 end
171 end 172 end
172 173