Mercurial > prosody-modules
comparison mod_storage_gdbm/mod_storage_gdbm.lua @ 1632:050d101af207
mod_storage_gdbm: Prefix archive item keys with username to prevent collisions
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 25 Mar 2015 17:44:03 +0100 |
parents | 98427ed3d53f |
children | 1d2dc6c74581 |
comparison
equal
deleted
inserted
replaced
1631:98427ed3d53f | 1632:050d101af207 |
---|---|
76 if is_stanza(value) then | 76 if is_stanza(value) then |
77 type, value = "stanza", st.preserialize(value); | 77 type, value = "stanza", st.preserialize(value); |
78 end | 78 end |
79 meta[i] = { key = key, when = when, with = with, type = type }; | 79 meta[i] = { key = key, when = when, with = with, type = type }; |
80 meta[key] = i; | 80 meta[key] = i; |
81 local ok, err = self:set(key, value); | 81 local prefix = (username or "@") .. "#"; |
82 local ok, err = self:set(prefix..key, value); | |
82 if not ok then return nil, err; end | 83 if not ok then return nil, err; end |
83 ok, err = self:set(username, meta); | 84 ok, err = self:set(username, meta); |
84 if not ok then return nil, err; end | 85 if not ok then return nil, err; end |
85 return key; | 86 return key; |
86 end | 87 end |
90 }; | 91 }; |
91 | 92 |
92 function archive:find(username, query) | 93 function archive:find(username, query) |
93 query = query or empty_query; | 94 query = query or empty_query; |
94 local meta = self:get(username) or empty; | 95 local meta = self:get(username) or empty; |
96 local prefix = (username or "@") .. "#"; | |
95 local r = query.reverse; | 97 local r = query.reverse; |
96 local d = t(r, -1, 1); | 98 local d = t(r, -1, 1); |
97 local s = meta[t(r, query.before, query.after)]; | 99 local s = meta[t(r, query.before, query.after)]; |
98 local limit = query.limit; | 100 local limit = query.limit; |
99 if s then | 101 if s then |
110 item = meta[i]; | 112 item = meta[i]; |
111 if (not query.with or item.with == query.with) | 113 if (not query.with or item.with == query.with) |
112 and (not query.start or item.when >= query.start) | 114 and (not query.start or item.when >= query.start) |
113 and (not query["end"] or item.when <= query["end"]) then | 115 and (not query["end"] or item.when <= query["end"]) then |
114 s = i + d; c = c + 1; | 116 s = i + d; c = c + 1; |
115 value = self:get(item.key); | 117 value = self:get(prefix..item.key); |
116 return item.key, (deserialize[item.type] or id)(value), item.when, item.with; | 118 return item.key, (deserialize[item.type] or id)(value), item.when, item.with; |
117 end | 119 end |
118 end | 120 end |
119 end | 121 end |
120 end | 122 end |