Comparison

plugins/muc/mod_muc.lua @ 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
parent 8707:fd39c44c0113
child 8833:9c90cd2fc4c3
comparison
equal deleted inserted replaced
8817:9a3066a580ad 8818:c96c00dc424b
122 room_state:set(node, nil); 122 room_state:set(node, nil);
123 return room_configs:set(node, nil); 123 return room_configs:set(node, nil);
124 end 124 end
125 end 125 end
126 126
127 local max_rooms = module:get_option_number("muc_max_rooms");
128 local max_live_rooms = module:get_option_number("muc_room_cache_size", 100);
129
127 local eviction_hit_rate = module:measure("room_eviction", "rate"); 130 local eviction_hit_rate = module:measure("room_eviction", "rate");
128 local rooms = cache.new(module:get_option_number("muc_room_cache_size", 100), function (jid, room) 131 local rooms = cache.new(max_rooms or max_live_rooms, function (jid, room)
132 if max_rooms then
133 module:log("info", "Room limit of %d reached, no new rooms allowed");
134 return false;
135 end
129 module:log("debug", "Evicting room %s", jid); 136 module:log("debug", "Evicting room %s", jid);
130 eviction_hit_rate(); 137 eviction_hit_rate();
131 room_items_cache[room.jid] = room:get_public() and room:get_name() or nil; 138 room_items_cache[room.jid] = room:get_public() and room:get_name() or nil;
132 local ok, err = room_save(room, nil, true); -- Force to disk 139 local ok, err = room_save(room, nil, true); -- Force to disk
133 if not ok then 140 if not ok then