Mercurial > prosody-modules
comparison mod_mam/mod_mam.lua @ 706:5c2b96c4dde6
mod_mam: Enforce a max number of items returned, with a default.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 08 Jun 2012 21:01:44 +0200 |
| parents | c9d0ba39a33b |
| children | f987c7b79008 |
comparison
equal
deleted
inserted
replaced
| 705:c9d0ba39a33b | 706:5c2b96c4dde6 |
|---|---|
| 19 local dm_list_append = require "util.datamanager".list_append; | 19 local dm_list_append = require "util.datamanager".list_append; |
| 20 local rm_load_roster = require "core.rostermanager".load_roster; | 20 local rm_load_roster = require "core.rostermanager".load_roster; |
| 21 | 21 |
| 22 local tostring = tostring; | 22 local tostring = tostring; |
| 23 local time_now = os.time; | 23 local time_now = os.time; |
| 24 local m_min = math.min;, | |
| 24 local timestamp, timestamp_parse = require "util.datetime".datetime, require "util.datetime".parse; | 25 local timestamp, timestamp_parse = require "util.datetime".datetime, require "util.datetime".parse; |
| 25 local uuid = require "util.uuid".generate; | 26 local uuid = require "util.uuid".generate; |
| 27 local default_max_items, max_max_items = 20, module:get_option_number("max_archive_query_results", 50); | |
| 26 local global_default_policy = module:get_option("default_archive_policy", false); | 28 local global_default_policy = module:get_option("default_archive_policy", false); |
| 27 -- TODO Should be possible to enforce it too | 29 -- TODO Should be possible to enforce it too |
| 30 | |
| 28 | 31 |
| 29 -- For translating preference names from string to boolean and back | 32 -- For translating preference names from string to boolean and back |
| 30 local default_attrs = { | 33 local default_attrs = { |
| 31 always = true, [true] = "always", | 34 always = true, [true] = "always", |
| 32 never = false, [false] = "never", | 35 never = false, [false] = "never", |
| 135 end | 138 end |
| 136 return true | 139 return true |
| 137 end | 140 end |
| 138 | 141 |
| 139 -- RSM stuff | 142 -- RSM stuff |
| 143 local qmax = m_min(qset and qset.max or default_max_items, max_max_items); | |
| 140 local qset_matches = not (qset and qset.after); | 144 local qset_matches = not (qset and qset.after); |
| 141 local first, last, index; | 145 local first, last, index; |
| 142 local n = 0; | 146 local n = 0; |
| 143 local start = qset and qset.index or 1; | 147 local start = qset and qset.index or 1; |
| 144 | 148 |
| 187 if qset then | 191 if qset then |
| 188 if qset.after == id then | 192 if qset.after == id then |
| 189 module:log("debug", "Start of matching range found"); | 193 module:log("debug", "Start of matching range found"); |
| 190 qset_matches = true; | 194 qset_matches = true; |
| 191 end | 195 end |
| 192 if qset.max and n >= qset.max then | 196 if n >= qmax then |
| 193 module:log("debug", "Max number of items matched"); | 197 module:log("debug", "Max number of items matched"); |
| 194 break | 198 break |
| 195 end | 199 end |
| 196 end | 200 end |
| 197 end | 201 end |
