aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_storage_sql.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2017-11-09 16:50:36 +0100
committerKim Alvefur <zash@zash.se>2017-11-09 16:50:36 +0100
commit01d628a5476f08dc53feb8700819360f8e38f0b9 (patch)
tree4e28639b4cd4097413cbff43fe39d046e81db218 /plugins/mod_storage_sql.lua
parent06addc9a735417f7194a0e579b05bc0c5d530a00 (diff)
downloadprosody-01d628a5476f08dc53feb8700819360f8e38f0b9.tar.gz
prosody-01d628a5476f08dc53feb8700819360f8e38f0b9.zip
mod_storage_sql: Add support for truncating deletion
Diffstat (limited to 'plugins/mod_storage_sql.lua')
-rw-r--r--plugins/mod_storage_sql.lua30
1 files changed, 29 insertions, 1 deletions
diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua
index 4c65b4f4..a9f81844 100644
--- a/plugins/mod_storage_sql.lua
+++ b/plugins/mod_storage_sql.lua
@@ -374,7 +374,35 @@ function archive_store:delete(username, query)
end
archive_where(query, args, where);
archive_where_id_range(query, args, where);
- sql_query = sql_query:format(t_concat(where, " AND "));
+ if query.truncate == nil then
+ sql_query = sql_query:format(t_concat(where, " AND "));
+ else
+ args[#args+1] = query.truncate;
+ local unlimited = "ALL";
+ if engine.params.driver == "SQLite3" then
+ sql_query = [[
+ DELETE FROM "prosodyarchive"
+ WHERE %s
+ ORDER BY "sort_id" %s
+ LIMIT %s OFFSET ?;
+ ]];
+ unlimited = "-1";
+ else
+ sql_query = [[
+ DELETE FROM "prosodyarchive"
+ WHERE "sort_id" IN (
+ SELECT "sort_id" FROM "prosodyarchive"
+ WHERE %s
+ ORDER BY "sort_id" %s
+ LIMIT %s OFFSET ?
+ );]];
+ if engine.params.driver == "MySQL" then
+ unlimited = "18446744073709551615";
+ end
+ end
+ sql_query = string.format(sql_query, t_concat(where, " AND "),
+ query.reverse and "ASC" or "DESC", unlimited);
+ end
return engine:delete(sql_query, unpack(args));
end);
return ok and stmt:affected(), stmt;