aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_storage_internal.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2017-10-09 01:01:28 +0200
committerKim Alvefur <zash@zash.se>2017-10-09 01:01:28 +0200
commit036a9369896e5980de00a9d4e9fc039486be7d49 (patch)
treec46f0ff2a17ae8b06ecaf457b5a32b8dd7f79dce /plugins/mod_storage_internal.lua
parent4f7c6ed3062cec890fd9ce31a3ee1d51effbe703 (diff)
downloadprosody-036a9369896e5980de00a9d4e9fc039486be7d49.tar.gz
prosody-036a9369896e5980de00a9d4e9fc039486be7d49.zip
mod_storage_internal: Add support for archive key deduplication (like mod_storage_sql)
Diffstat (limited to 'plugins/mod_storage_internal.lua')
-rw-r--r--plugins/mod_storage_internal.lua23
1 files changed, 21 insertions, 2 deletions
diff --git a/plugins/mod_storage_internal.lua b/plugins/mod_storage_internal.lua
index 76052575..9f44866a 100644
--- a/plugins/mod_storage_internal.lua
+++ b/plugins/mod_storage_internal.lua
@@ -44,17 +44,36 @@ local archive = {};
driver.archive = { __index = archive };
function archive:append(username, key, value, when, with)
- key = key or id();
when = when or now();
if not st.is_stanza(value) then
return nil, "unsupported-datatype";
end
value = st.preserialize(st.clone(value));
- value.key = key;
value.when = when;
value.with = with;
value.attr.stamp = datetime.datetime(when);
value.attr.stamp_legacy = datetime.legacy(when);
+
+ if key then
+ local items, err = datamanager.list_load(username, host, self.store);
+ if not items and err then return items, err; end
+ if items then
+ items = array(items);
+ items:filter(function (item)
+ return item.key ~= key;
+ end);
+ value.key = key;
+ items:push(value);
+ local ok, err = datamanager.list_store(username, host, self.store, items);
+ if not ok then return ok, err; end
+ return key;
+ end
+ else
+ key = id();
+ end
+
+ value.key = key;
+
local ok, err = datamanager.list_append(username, host, self.store, value);
if not ok then return ok, err; end
return key;