mod_http_upload: Skip write if nothing expired when checking
authorKim Alvefur <zash@zash.se>
Thu, 29 Aug 2019 23:35:42 +0200
changeset 3663 bb8a6df5ecba
parent 3662 02a1615d0392
child 3664 11cd6e034fd3
mod_http_upload: Skip write if nothing expired when checking Reducing unnecessary IO is good.
mod_http_upload/mod_http_upload.lua
--- a/mod_http_upload/mod_http_upload.lua	Thu Aug 29 23:30:55 2019 +0200
+++ b/mod_http_upload/mod_http_upload.lua	Thu Aug 29 23:35:42 2019 +0200
@@ -119,6 +119,7 @@
 	uploads = array(uploads);
 	local expiry = os.time() - max_age;
 	local upload_window = os.time() - 900;
+	local before = #uploads;
 	uploads:filter(function (item)
 		local filename = item.filename;
 		if item.dir then
@@ -136,6 +137,8 @@
 		end
 		return true;
 	end);
+	local after = #uploads;
+	if before == after then return true end -- nothing changed, skip write
 	return datamanager.list_store(username, host, module.name, uploads);
 end