Software /
code /
prosody
Comparison
plugins/mod_storage_internal.lua @ 8309:5281c479955a
mod_storage_internal: Add support for archive key deduplication (like mod_storage_sql)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 09 Oct 2017 01:01:28 +0200 |
parent | 8173:3ff99d49082f |
child | 8310:1759491b53db |
comparison
equal
deleted
inserted
replaced
8308:ab189d3f55d1 | 8309:5281c479955a |
---|---|
42 | 42 |
43 local archive = {}; | 43 local archive = {}; |
44 driver.archive = { __index = archive }; | 44 driver.archive = { __index = archive }; |
45 | 45 |
46 function archive:append(username, key, value, when, with) | 46 function archive:append(username, key, value, when, with) |
47 key = key or id(); | |
48 when = when or now(); | 47 when = when or now(); |
49 if not st.is_stanza(value) then | 48 if not st.is_stanza(value) then |
50 return nil, "unsupported-datatype"; | 49 return nil, "unsupported-datatype"; |
51 end | 50 end |
52 value = st.preserialize(st.clone(value)); | 51 value = st.preserialize(st.clone(value)); |
53 value.key = key; | |
54 value.when = when; | 52 value.when = when; |
55 value.with = with; | 53 value.with = with; |
56 value.attr.stamp = datetime.datetime(when); | 54 value.attr.stamp = datetime.datetime(when); |
57 value.attr.stamp_legacy = datetime.legacy(when); | 55 value.attr.stamp_legacy = datetime.legacy(when); |
56 | |
57 if key then | |
58 local items, err = datamanager.list_load(username, host, self.store); | |
59 if not items and err then return items, err; end | |
60 if items then | |
61 items = array(items); | |
62 items:filter(function (item) | |
63 return item.key ~= key; | |
64 end); | |
65 value.key = key; | |
66 items:push(value); | |
67 local ok, err = datamanager.list_store(username, host, self.store, items); | |
68 if not ok then return ok, err; end | |
69 return key; | |
70 end | |
71 else | |
72 key = id(); | |
73 end | |
74 | |
75 value.key = key; | |
76 | |
58 local ok, err = datamanager.list_append(username, host, self.store, value); | 77 local ok, err = datamanager.list_append(username, host, self.store, value); |
59 if not ok then return ok, err; end | 78 if not ok then return ok, err; end |
60 return key; | 79 return key; |
61 end | 80 end |
62 | 81 |