Comparison

mod_mam/mamprefs.lib.lua @ 1137:431627b07b9f

mod_mam/mamprefs.lib: Cache prefs in memory to save storage calls
author Kim Alvefur <zash@zash.se>
date Sat, 10 Aug 2013 20:42:56 +0200
parent 1136:a6d4508f7f28
child 1153:572b1ad46182
comparison
equal deleted inserted replaced
1136:a6d4508f7f28 1137:431627b07b9f
13 ["romeo@montague.net"] = true, -- always 13 ["romeo@montague.net"] = true, -- always
14 ["montague@montague.net"] = false, -- newer 14 ["montague@montague.net"] = false, -- newer
15 }; 15 };
16 end 16 end
17 17
18 local sessions = hosts[module.host].sessions;
18 local prefs = module:open_store("archive2_prefs"); 19 local prefs = module:open_store("archive2_prefs");
20
19 local function get_prefs(user) 21 local function get_prefs(user)
20 return prefs:get(user) or { [false] = global_default_policy }; 22 local user_sessions = sessions[user];
23 local user_prefs = user_sessions and user_sessions.archive_prefs
24 if not user_prefs and user_sessions then
25 user_prefs = prefs:get(user);
26 user_sessions.archive_prefs = user_prefs;
27 end
28 return user_prefs or { [false] = { default = global_default_policy } };
21 end 29 end
22 local function set_prefs(user, user_prefs) 30 local function set_prefs(user, user_prefs)
31 local user_sessions = sessions[user];
32 if user_sessions then
33 user_sessions.archive_prefs = user_prefs;
34 end
23 return prefs:set(user, user_prefs); 35 return prefs:set(user, user_prefs);
24 end 36 end
25 37
26 return { 38 return {
27 get = get_prefs, 39 get = get_prefs,