Comparison

plugins/mod_storage_memory.lua @ 11277:1256f32f21b6

mod_storage_memory: Support query for set of IDs
author Kim Alvefur <zash@zash.se>
date Tue, 12 Jan 2021 18:06:33 +0100
parent 11274:ecbfde402364
child 12977:74b9e05af71e
comparison
equal deleted inserted replaced
11276:7b2ee8995af9 11277:1256f32f21b6
2 local array = require "util.array"; 2 local array = require "util.array";
3 local envload = require "util.envload".envload; 3 local envload = require "util.envload".envload;
4 local st = require "util.stanza"; 4 local st = require "util.stanza";
5 local is_stanza = st.is_stanza or function (s) return getmetatable(s) == st.stanza_mt end 5 local is_stanza = st.is_stanza or function (s) return getmetatable(s) == st.stanza_mt end
6 local new_id = require "util.id".medium; 6 local new_id = require "util.id".medium;
7 local set = require "util.set";
7 8
8 local auto_purge_enabled = module:get_option_boolean("storage_memory_temporary", false); 9 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", {}); 10 local auto_purge_stores = module:get_option_set("storage_memory_temporary_stores", {});
10 11
11 local archive_item_limit = module:get_option_number("storage_archive_item_limit", 1000); 12 local archive_item_limit = module:get_option_number("storage_archive_item_limit", 1000);
56 archive_store.caps = { 57 archive_store.caps = {
57 total = true; 58 total = true;
58 quota = archive_item_limit; 59 quota = archive_item_limit;
59 truncate = true; 60 truncate = true;
60 full_id_range = true; 61 full_id_range = true;
62 ids = true;
61 }; 63 };
62 64
63 function archive_store:append(username, key, value, when, with) 65 function archive_store:append(username, key, value, when, with)
64 if is_stanza(value) then 66 if is_stanza(value) then
65 value = st.preserialize(value); 67 value = st.preserialize(value);
106 if query then 108 if query then
107 items = array():append(items); 109 items = array():append(items);
108 if query.key then 110 if query.key then
109 items:filter(function (item) 111 items:filter(function (item)
110 return item.key == query.key; 112 return item.key == query.key;
113 end);
114 end
115 if query.ids then
116 local ids = set.new(query.ids);
117 items:filter(function (item)
118 return ids:contains(item.key);
111 end); 119 end);
112 end 120 end
113 if query.with then 121 if query.with then
114 items:filter(function (item) 122 items:filter(function (item)
115 return item.with == query.with; 123 return item.with == query.with;