diff options
author | Kim Alvefur <zash@zash.se> | 2019-02-25 15:51:55 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2019-02-25 15:51:55 +0100 |
commit | aea959880cf8ae4d81c41d4e6ef224cc978ef278 (patch) | |
tree | 977219e3e289ec75cb1efde36a48f8a72ad3be04 /plugins/mod_storage_sql.lua | |
parent | c1a1511e2662fdd1749c30cfc1cabc3d4b89f082 (diff) | |
download | prosody-aea959880cf8ae4d81c41d4e6ef224cc978ef278.tar.gz prosody-aea959880cf8ae4d81c41d4e6ef224cc978ef278.zip |
mod_storage_sql: Implement archive summary API
Diffstat (limited to 'plugins/mod_storage_sql.lua')
-rw-r--r-- | plugins/mod_storage_sql.lua | 35 |
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; |