Changeset

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 705:c9d0ba39a33b
children 707:f987c7b79008
files mod_mam/mod_mam.lua
diffstat 1 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mod_mam/mod_mam.lua	Fri Jun 08 20:11:39 2012 +0200
+++ b/mod_mam/mod_mam.lua	Fri Jun 08 21:01:44 2012 +0200
@@ -21,11 +21,14 @@
 
 local tostring = tostring;
 local time_now = os.time;
+local m_min = math.min;,
 local timestamp, timestamp_parse = require "util.datetime".datetime, require "util.datetime".parse;
 local uuid = require "util.uuid".generate;
+local default_max_items, max_max_items = 20, module:get_option_number("max_archive_query_results", 50);
 local global_default_policy = module:get_option("default_archive_policy", false);
 -- TODO Should be possible to enforce it too
 
+
 -- For translating preference names from string to boolean and back
 local default_attrs = {
 	always = true, [true] = "always",
@@ -137,6 +140,7 @@
 		end
 
 		-- RSM stuff
+		local qmax = m_min(qset and qset.max or default_max_items, max_max_items);
 		local qset_matches = not (qset and qset.after);
 		local first, last, index;
 		local n = 0;
@@ -189,7 +193,7 @@
 					module:log("debug", "Start of matching range found");
 					qset_matches = true;
 				end
-				if qset.max and n >= qset.max then
+				if n >= qmax then
 					module:log("debug", "Max number of items matched");
 					break
 				end