comparison mod_storage_gdbm/mod_storage_gdbm.lua @ 1628:5e4b37b9cde1

mod_storage_gdbm: Fix traceback if query is nil or no metadata exists
author Kim Alvefur <zash@zash.se>
date Wed, 25 Mar 2015 17:29:54 +0100
parents 53052a610c67
children 36eb0dbea7ba
comparison
equal deleted inserted replaced
1627:458c80904525 1628:5e4b37b9cde1
12 local uuid = require"util.uuid".generate; 12 local uuid = require"util.uuid".generate;
13 local serialization = require"util.serialization"; 13 local serialization = require"util.serialization";
14 local st = require"util.stanza"; 14 local st = require"util.stanza";
15 local serialize = serialization.serialize; 15 local serialize = serialization.serialize;
16 local deserialize = serialization.deserialize; 16 local deserialize = serialization.deserialize;
17
18 local empty = {};
17 19
18 local function id(v) return v; end 20 local function id(v) return v; end
19 21
20 local function is_stanza(s) 22 local function is_stanza(s)
21 return getmetatable(s) == st.stanza_mt; 23 return getmetatable(s) == st.stanza_mt;
74 local deserialize = { 76 local deserialize = {
75 stanza = st.deserialize; 77 stanza = st.deserialize;
76 }; 78 };
77 79
78 function archive:find(username, query) 80 function archive:find(username, query)
79 local meta = self:get(username); 81 query = query or empty_query;
82 local meta = self:get(username) or empty;
80 local r = query.reverse; 83 local r = query.reverse;
81 local d = r and -1 or 1; 84 local d = r and -1 or 1;
82 local s = meta[ifelse(r, query.before, query.after)]; 85 local s = meta[ifelse(r, query.before, query.after)];
83 local limit = query.limit; 86 local limit = query.limit;
84 if s then 87 if s then