Mercurial > prosody-hg
comparison plugins/mod_storage_memory.lua @ 9887:69f810014853
mod_storage_memory: Add support for archive item limits
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Wed, 20 Mar 2019 12:14:45 +0100 |
| parents | 18f025b3987d |
| children | 6d50efaee148 |
comparison
equal
deleted
inserted
replaced
| 9886:710a116341cd | 9887:69f810014853 |
|---|---|
| 6 local new_id = require "util.id".medium; | 6 local new_id = require "util.id".medium; |
| 7 | 7 |
| 8 local auto_purge_enabled = module:get_option_boolean("storage_memory_temporary", false); | 8 local auto_purge_enabled = module:get_option_boolean("storage_memory_temporary", false); |
| 9 local auto_purge_stores = module:get_option_set("storage_memory_temporary_stores", {}); | 9 local auto_purge_stores = module:get_option_set("storage_memory_temporary_stores", {}); |
| 10 | 10 |
| 11 local archive_item_limit = module:get_option_number("storage_archive_item_limit", 1000); | |
| 12 | |
| 11 local memory = setmetatable({}, { | 13 local memory = setmetatable({}, { |
| 12 __index = function(t, k) | 14 __index = function(t, k) |
| 13 local store = module:shared(k) | 15 local store = module:shared(k) |
| 14 t[k] = store; | 16 t[k] = store; |
| 15 return store; | 17 return store; |
| 48 | 50 |
| 49 local archive_store = {}; | 51 local archive_store = {}; |
| 50 archive_store.__index = archive_store; | 52 archive_store.__index = archive_store; |
| 51 | 53 |
| 52 archive_store.users = _users; | 54 archive_store.users = _users; |
| 55 | |
| 56 archive_store.caps = { | |
| 57 total = true; | |
| 58 quota = archive_item_limit; | |
| 59 truncate = true; | |
| 60 }; | |
| 53 | 61 |
| 54 function archive_store:append(username, key, value, when, with) | 62 function archive_store:append(username, key, value, when, with) |
| 55 if is_stanza(value) then | 63 if is_stanza(value) then |
| 56 value = st.preserialize(value); | 64 value = st.preserialize(value); |
| 57 value = envload("return xml"..serialize(value), "=(stanza)", { xml = st.deserialize }) | 65 value = envload("return xml"..serialize(value), "=(stanza)", { xml = st.deserialize }) |
| 68 key = new_id(); | 76 key = new_id(); |
| 69 v.key = key; | 77 v.key = key; |
| 70 end | 78 end |
| 71 if a[key] then | 79 if a[key] then |
| 72 table.remove(a, a[key]); | 80 table.remove(a, a[key]); |
| 81 elseif #a >= archive_item_limit then | |
| 82 return nil, "quota-limit"; | |
| 73 end | 83 end |
| 74 local i = #a+1; | 84 local i = #a+1; |
| 75 a[i] = v; | 85 a[i] = v; |
| 76 a[key] = i; | 86 a[key] = i; |
| 77 return key; | 87 return key; |
