aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2019-02-25 15:51:55 +0100
committerKim Alvefur <zash@zash.se>2019-02-25 15:51:55 +0100
commita32b5ceb4576f8fefeea0f68aae1f81dd942125d (patch)
tree977219e3e289ec75cb1efde36a48f8a72ad3be04 /plugins
parent582fa3f46f105fe55447d607dceb43b5ac61d440 (diff)
downloadprosody-a32b5ceb4576f8fefeea0f68aae1f81dd942125d.tar.gz
prosody-a32b5ceb4576f8fefeea0f68aae1f81dd942125d.zip
mod_storage_sql: Implement archive summary API
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_storage_sql.lua35
1 files changed, 35 insertions, 0 deletions
diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua
index 6b26759f..ffe48ab8 100644
--- a/plugins/mod_storage_sql.lua
+++ b/plugins/mod_storage_sql.lua
@@ -419,6 +419,41 @@ function archive_store:find(username, query)
end, total;
end
+function archive_store:summary(username, query)
+ query = query or {};
+ local user,store = username,self.store;
+ local ok, result = engine:transaction(function()
+ local sql_query = [[
+ SELECT DISTINCT "with", COUNT(*)
+ FROM "prosodyarchive"
+ WHERE %s
+ GROUP BY "with"
+ ORDER BY "sort_id" %s%s;
+ ]];
+ local args = { host, user or "", store, };
+ local where = { "\"host\" = ?", "\"user\" = ?", "\"store\" = ?", };
+
+ archive_where(query, args, where);
+
+ archive_where_id_range(query, args, where);
+
+ if query.limit then
+ 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 "");
+ return engine:select(sql_query, unpack(args));
+ end);
+ if not ok then return ok, result end
+ local summary = {};
+ for row in result do
+ local with, count = row[1], row[2];
+ summary[with] = count;
+ end
+ return summary;
+end
+
function archive_store:delete(username, query)
query = query or {};
local user,store = username,self.store;