Diff

plugins/mod_storage_sql2.lua @ 5968:e1e9f1411442

mod_storage_sql2: Include user, host and store in id lookup
author Kim Alvefur <zash@zash.se>
date Wed, 25 Dec 2013 15:28:55 +0100
parent 5913:6865eecaf5a5
child 5969:0a3b8003ac9c
line wrap: on
line diff
--- a/plugins/mod_storage_sql2.lua	Wed Dec 18 18:36:54 2013 +0100
+++ b/plugins/mod_storage_sql2.lua	Wed Dec 25 15:28:55 2013 +0100
@@ -256,14 +256,16 @@
 	end
 end
 local function archive_where_id_range(query, args, where)
+	local args_len = #args
 	-- Before or after specific item, exclusive
 	if query.after then  -- keys better be unique!
-		where[#where+1] = "`sort_id` > (SELECT `sort_id` FROM `prosodyarchive` WHERE `key` = ? LIMIT 1)"
-		args[#args+1] = query.after
+		where[#where+1] = "`sort_id` > (SELECT `sort_id` FROM `prosodyarchive` WHERE `key` = ? AND `host` = ?`AND user` = ?`AND store` = ?  LIMIT 1)"
+		args[args_len+1], args[args_len+2], args[args_len+3], args[args_len+4] = query.after, args[1], args[2], args[3];
+		args_len = args_len + 4
 	end
 	if query.before then
-		where[#where+1] = "`sort_id` < (SELECT `sort_id` FROM `prosodyarchive` WHERE `key` = ? LIMIT 1)"
-		args[#args+1] = query.before
+		where[#where+1] = "`sort_id` < (SELECT `sort_id` FROM `prosodyarchive` WHERE `key` = ? AND `host` = ?`AND user` = ?`AND store` = ?  LIMIT 1)"
+		args[args_len+1], args[args_len+2], args[args_len+3], args[args_len+4] = query.before, args[1], args[2], args[3];
 	end
 end