Software / code / prosody
Comparison
plugins/mod_storage_internal.lua @ 11278:c3907f05bed4
mod_storage_internal: Support query for set of IDs
Based on implementation in mod_storage_memory
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Tue, 12 Jan 2021 18:06:55 +0100 |
| parent | 11275:b8fada57faf0 |
| child | 11765:1cac469b18d0 |
comparison
equal
deleted
inserted
replaced
| 11277:1256f32f21b6 | 11278:c3907f05bed4 |
|---|---|
| 4 local datetime = require "util.datetime"; | 4 local datetime = require "util.datetime"; |
| 5 local st = require "util.stanza"; | 5 local st = require "util.stanza"; |
| 6 local now = require "util.time".now; | 6 local now = require "util.time".now; |
| 7 local id = require "util.id".medium; | 7 local id = require "util.id".medium; |
| 8 local jid_join = require "util.jid".join; | 8 local jid_join = require "util.jid".join; |
| 9 local set = require "util.set"; | |
| 9 | 10 |
| 10 local host = module.host; | 11 local host = module.host; |
| 11 | 12 |
| 12 local archive_item_limit = module:get_option_number("storage_archive_item_limit", 10000); | 13 local archive_item_limit = module:get_option_number("storage_archive_item_limit", 10000); |
| 13 local archive_item_count_cache = cache.new(module:get_option("storage_archive_item_limit_cache_size", 1000)); | 14 local archive_item_count_cache = cache.new(module:get_option("storage_archive_item_limit_cache_size", 1000)); |
| 51 archive.caps = { | 52 archive.caps = { |
| 52 total = true; | 53 total = true; |
| 53 quota = archive_item_limit; | 54 quota = archive_item_limit; |
| 54 truncate = true; | 55 truncate = true; |
| 55 full_id_range = true; | 56 full_id_range = true; |
| 57 ids = true; | |
| 56 }; | 58 }; |
| 57 | 59 |
| 58 function archive:append(username, key, value, when, with) | 60 function archive:append(username, key, value, when, with) |
| 59 when = when or now(); | 61 when = when or now(); |
| 60 if not st.is_stanza(value) then | 62 if not st.is_stanza(value) then |
| 140 if query then | 142 if query then |
| 141 items = array(items); | 143 items = array(items); |
| 142 if query.key then | 144 if query.key then |
| 143 items:filter(function (item) | 145 items:filter(function (item) |
| 144 return item.key == query.key; | 146 return item.key == query.key; |
| 147 end); | |
| 148 end | |
| 149 if query.ids then | |
| 150 local ids = set.new(query.ids); | |
| 151 items:filter(function (item) | |
| 152 return ids:contains(item.key); | |
| 145 end); | 153 end); |
| 146 end | 154 end |
| 147 if query.with then | 155 if query.with then |
| 148 items:filter(function (item) | 156 items:filter(function (item) |
| 149 return item.with == query.with; | 157 return item.with == query.with; |