mod_storage_sql: Fix summary API with Postgres (fixes #1766) 0.12
authorKim Alvefur <zash@zash.se>
Fri, 22 Jul 2022 19:09:50 +0200
branch0.12
changeset 12603 5aafcf6a0730
parent 12602 a2624315d30e
child 12604 3d3a0c4e2662
child 12641 2200f0c6b3f1
mod_storage_sql: Fix summary API with Postgres (fixes #1766) The ORDER BY and LIMIT clauses are not needed and don't even make much sense. This part was most likely a leftover from the :find method. Tested with sqlite and postgres 14
plugins/mod_storage_sql.lua
--- a/plugins/mod_storage_sql.lua	Fri Jul 22 18:32:45 2022 +0200
+++ b/plugins/mod_storage_sql.lua	Fri Jul 22 19:09:50 2022 +0200
@@ -544,8 +544,7 @@
 		SELECT DISTINCT "with", COUNT(*), MIN("when"), MAX("when")
 		FROM "prosodyarchive"
 		WHERE %s
-		GROUP BY "with"
-		ORDER BY "sort_id" %s%s;
+		GROUP BY "with";
 		]];
 		local args = { host, user or "", store, };
 		local where = { "\"host\" = ?", "\"user\" = ?", "\"store\" = ?", };
@@ -558,8 +557,7 @@
 			args[#args+1] = query.limit;
 		end
 
-		sql_query = sql_query:format(t_concat(where, " AND "), query.reverse
-			and "DESC" or "ASC", query.limit and " LIMIT ?" or "");
+		sql_query = sql_query:format(t_concat(where, " AND "));
 		return engine:select(sql_query, unpack(args));
 	end);
 	if not ok then return ok, result end