aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-12-03 08:21:29 +0100
committerKim Alvefur <zash@zash.se>2021-12-03 08:21:29 +0100
commit62ff00cd1f65ec585c0f069566bf56c90bcd9bd8 (patch)
treec514b52ec81ce82af47e206ee85d8407d6b5fa31
parenta3d8a25bdd7502231e24ed5ca1b19d3790a48bbc (diff)
downloadprosody-62ff00cd1f65ec585c0f069566bf56c90bcd9bd8.tar.gz
prosody-62ff00cd1f65ec585c0f069566bf56c90bcd9bd8.zip
mod_http_file_share: Keep track of total storage use across restarts
The value needs to be known in order to determine if additional uploads can be accepted.
-rw-r--r--plugins/mod_http_file_share.lua5
1 files changed, 5 insertions, 0 deletions
diff --git a/plugins/mod_http_file_share.lua b/plugins/mod_http_file_share.lua
index 0f431343..ce49bc26 100644
--- a/plugins/mod_http_file_share.lua
+++ b/plugins/mod_http_file_share.lua
@@ -28,6 +28,7 @@ module:add_identity("store", "file", module:get_option_string("name", "HTTP File
module:add_feature(namespace);
local uploads = module:open_store("uploads", "archive");
+local persist_stats = module:open_store("upload_stats", "map");
-- id, <request>, time, owner
local secret = module:get_option_string(module.name.."_secret", require"util.id".long());
@@ -72,6 +73,8 @@ local measure_upload_cache_size = module:measure("upload_cache", "amount");
local measure_quota_cache_size = module:measure("quota_cache", "amount");
local measure_total_storage_usage = nil;
if total_storage_limit then
+ local total, err = persist_stats:get(nil, "total");
+ if not err then total_storage_usage = tonumber(total) or 0; end
measure_total_storage_usage = module:measure("total_storage", "amount", { unit = "bytes" });
end
@@ -513,6 +516,7 @@ if expiry >= 0 and not external_base_url then
if total_storage_usage then
total_storage_usage = total_storage_usage - size_sum;
module:log("debug", "Global quota %s / %s", B(total_storage_usage), B(total_storage_limit));
+ persist_stats:set(nil, "total", total_storage_usage);
end
if #obsolete_uploads == 0 then
@@ -547,6 +551,7 @@ if total_storage_limit then
module:log("info", "Uploaded files total: %s in %d files", B(sum), count);
total_storage_usage = sum;
module:log("debug", "Global quota %s / %s", B(total_storage_usage), B(total_storage_limit));
+ persist_stats:set(nil, "total", sum);
summary_done();
end);