mod_blocklist: Check first level cache before calling blocklist getter
authorKim Alvefur <zash@zash.se>
Mon, 05 Dec 2016 17:35:38 +0100
changeset 7778 3733bdbe0b22
parent 7777 1f55edac1f72
child 7779 63f50a84318f
mod_blocklist: Check first level cache before calling blocklist getter
plugins/mod_blocklist.lua
--- a/plugins/mod_blocklist.lua	Thu Dec 08 18:06:18 2016 +0100
+++ b/plugins/mod_blocklist.lua	Mon Dec 05 17:35:38 2016 +0100
@@ -77,10 +77,7 @@
 end
 
 local function get_blocklist(username)
-	local blocklist = cache[username];
-	if not blocklist then
-		blocklist = cache2:get(username);
-	end
+	local blocklist = cache2:get(username);
 	if not blocklist then
 		if not user_exists(username, module.host) then
 			return null_blocklist;
@@ -102,7 +99,7 @@
 	local origin, stanza = event.origin, event.stanza;
 	local username = origin.username;
 	local reply = st.reply(stanza):tag("blocklist", { xmlns = "urn:xmpp:blocking" });
-	local blocklist = get_blocklist(username);
+	local blocklist = cache[username] or get_blocklist(username);
 	for jid in pairs(blocklist) do
 		if jid then
 			reply:tag("item", { jid = jid }):up();
@@ -156,7 +153,7 @@
 		return true;
 	end
 
-	local blocklist = get_blocklist(username);
+	local blocklist = cache[username] or get_blocklist(username);
 
 	local new_blocklist = {
 		-- We set the [false] key to someting as a signal not to migrate privacy lists