Diff

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
line wrap: on
line diff
--- a/mod_mam/mamprefs.lib.lua	Sat Aug 10 20:39:24 2013 +0200
+++ b/mod_mam/mamprefs.lib.lua	Sat Aug 10 20:42:56 2013 +0200
@@ -15,11 +15,23 @@
 	};
 end
 
+local sessions = hosts[module.host].sessions;
 local prefs = module:open_store("archive2_prefs");
+
 local function get_prefs(user)
-	return prefs:get(user) or { [false] = global_default_policy };
+	local user_sessions = sessions[user];
+	local user_prefs = user_sessions and user_sessions.archive_prefs
+	if not user_prefs and user_sessions then
+		user_prefs = prefs:get(user);
+		user_sessions.archive_prefs = user_prefs;
+	end
+	return user_prefs or { [false] = { default = global_default_policy } };
 end
 local function set_prefs(user, user_prefs)
+	local user_sessions = sessions[user];
+	if user_sessions then
+		user_sessions.archive_prefs = user_prefs;
+	end
 	return prefs:set(user, user_prefs);
 end