Comparison

plugins/mod_blocklist.lua @ 7775:3733bdbe0b22

mod_blocklist: Check first level cache before calling blocklist getter
author Kim Alvefur <zash@zash.se>
date Mon, 05 Dec 2016 17:35:38 +0100
parent 7774:1f55edac1f72
child 7968:f0e35f4db9e0
comparison
equal deleted inserted replaced
7774:1f55edac1f72 7775:3733bdbe0b22
75 set_blocklist(username, migrated_data); 75 set_blocklist(username, migrated_data);
76 return migrated_data; 76 return migrated_data;
77 end 77 end
78 78
79 local function get_blocklist(username) 79 local function get_blocklist(username)
80 local blocklist = cache[username]; 80 local blocklist = cache2:get(username);
81 if not blocklist then
82 blocklist = cache2:get(username);
83 end
84 if not blocklist then 81 if not blocklist then
85 if not user_exists(username, module.host) then 82 if not user_exists(username, module.host) then
86 return null_blocklist; 83 return null_blocklist;
87 end 84 end
88 blocklist = storage:get(username); 85 blocklist = storage:get(username);
100 97
101 module:hook("iq-get/self/urn:xmpp:blocking:blocklist", function (event) 98 module:hook("iq-get/self/urn:xmpp:blocking:blocklist", function (event)
102 local origin, stanza = event.origin, event.stanza; 99 local origin, stanza = event.origin, event.stanza;
103 local username = origin.username; 100 local username = origin.username;
104 local reply = st.reply(stanza):tag("blocklist", { xmlns = "urn:xmpp:blocking" }); 101 local reply = st.reply(stanza):tag("blocklist", { xmlns = "urn:xmpp:blocking" });
105 local blocklist = get_blocklist(username); 102 local blocklist = cache[username] or get_blocklist(username);
106 for jid in pairs(blocklist) do 103 for jid in pairs(blocklist) do
107 if jid then 104 if jid then
108 reply:tag("item", { jid = jid }):up(); 105 reply:tag("item", { jid = jid }):up();
109 end 106 end
110 end 107 end
154 -- <block/> element does not contain at least one <item/> child element 151 -- <block/> element does not contain at least one <item/> child element
155 origin.send(st_error_reply(stanza, "modify", "bad-request")); 152 origin.send(st_error_reply(stanza, "modify", "bad-request"));
156 return true; 153 return true;
157 end 154 end
158 155
159 local blocklist = get_blocklist(username); 156 local blocklist = cache[username] or get_blocklist(username);
160 157
161 local new_blocklist = { 158 local new_blocklist = {
162 -- We set the [false] key to someting as a signal not to migrate privacy lists 159 -- We set the [false] key to someting as a signal not to migrate privacy lists
163 [false] = blocklist[false] or { created = os.time(); }; 160 [false] = blocklist[false] or { created = os.time(); };
164 }; 161 };