# HG changeset patch # User Kim Alvefur # Date 1638516089 -3600 # Node ID 9d2eab56f12437507b9cee5e037c7ceaf77fcc88 # Parent 99be6874340b84d96733257be2e850757d469de9 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. diff -r 99be6874340b -r 9d2eab56f124 plugins/mod_http_file_share.lua --- 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, , 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);