Changeset

8818:c96c00dc424b

MUC: Add support for an optional hard limit on number of rooms (fixes #766)
author Kim Alvefur <zash@zash.se>
date Tue, 22 May 2018 21:22:51 +0200
parents 8817:9a3066a580ad
children 8820:1348a931528a
files plugins/muc/mod_muc.lua
diffstat 1 files changed, 8 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/muc/mod_muc.lua	Sun May 20 15:20:34 2018 +0200
+++ b/plugins/muc/mod_muc.lua	Tue May 22 21:22:51 2018 +0200
@@ -124,8 +124,15 @@
 	end
 end
 
+local max_rooms = module:get_option_number("muc_max_rooms");
+local max_live_rooms = module:get_option_number("muc_room_cache_size", 100);
+
 local eviction_hit_rate = module:measure("room_eviction", "rate");
-local rooms = cache.new(module:get_option_number("muc_room_cache_size", 100), function (jid, room)
+local rooms = cache.new(max_rooms or max_live_rooms, function (jid, room)
+	if max_rooms then
+		module:log("info", "Room limit of %d reached, no new rooms allowed");
+		return false;
+	end
 	module:log("debug", "Evicting room %s", jid);
 	eviction_hit_rate();
 	room_items_cache[room.jid] = room:get_public() and room:get_name() or nil;