Changeset

11999:9d2eab56f124

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.
author Kim Alvefur <zash@zash.se>
date Fri, 03 Dec 2021 08:21:29 +0100
parents 11998:99be6874340b
children 12000:00c57684cf20
files plugins/mod_http_file_share.lua
diffstat 1 files changed, 5 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_http_file_share.lua	Fri Dec 03 08:16:18 2021 +0100
+++ b/plugins/mod_http_file_share.lua	Fri Dec 03 08:21:29 2021 +0100
@@ -28,6 +28,7 @@
 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_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 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 @@
 		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);