# HG changeset patch # User Kim Alvefur # Date 1498218683 -7200 # Node ID 02d688ba7739bec8e84f3ea9dda6b295a8c52a86 # Parent 14f62b9711607d826da9cfeb08b44a6e2e68442b mod_mam_muc: Make calculation of max history length more like in mod_muc diff -r 14f62b971160 -r 02d688ba7739 mod_mam_muc/README.markdown --- a/mod_mam_muc/README.markdown Thu May 25 16:47:29 2017 +0200 +++ b/mod_mam_muc/README.markdown Fri Jun 23 13:51:23 2017 +0200 @@ -41,11 +41,8 @@ muc_log_all_rooms = false; -- set to true to force logging of all rooms --- This is the largest number of messages that are allowed to be retrieved in one MAM request. -max_archive_query_results = 20; - -- This is the largest number of messages that are allowed to be retrieved when joining a room. -max_history_messages = 1000; +max_history_messages = 20; ``` Compatibility diff -r 14f62b971160 -r 02d688ba7739 mod_mam_muc/mod_mam_muc.lua --- a/mod_mam_muc/mod_mam_muc.lua Thu May 25 16:47:29 2017 +0200 +++ b/mod_mam_muc/mod_mam_muc.lua Fri Jun 23 13:51:23 2017 +0200 @@ -40,8 +40,13 @@ local time_now = os.time; local m_min = math.min; local timestamp, timestamp_parse = require "util.datetime".datetime, require "util.datetime".parse; -local max_history_length = module:get_option_number("max_history_messages", 1000); -local default_max_items, max_max_items = 20, module:get_option_number("max_archive_query_results", max_history_length); + +local default_history_length = 20; +local max_history_length = module:get_option_number("max_history_messages", math.huge); + +local function get_historylength(room) + return math.min(room._data.history_length or default_history_length, max_history_length); +end local log_all_rooms = module:get_option_boolean("muc_log_all_rooms", false); local log_by_default = module:get_option_boolean("muc_log_by_default", true); @@ -200,7 +205,7 @@ -- RSM stuff local qset = rsm.get(query); - local qmax = m_min(qset and qset.max or default_max_items, max_max_items); + local qmax = m_min(qset and qset.max or 20, 20); local reverse = qset and qset.before or false; local before, after = qset and qset.before, qset and qset.after; @@ -285,7 +290,7 @@ -- Load all the data! local query = { - limit = m_min(maxstanzas or 20, max_history_length); + limit = math.min(maxstanzas, get_historylength(room)); start = since; reverse = true; with = "message