Mercurial > prosody-modules
comparison mod_http_upload/mod_http_upload.lua @ 3659:bb8a6df5ecba
mod_http_upload: Skip write if nothing expired when checking
Reducing unnecessary IO is good.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 29 Aug 2019 23:35:42 +0200 |
parents | 02a1615d0392 |
children | 88d414c916ee |
comparison
equal
deleted
inserted
replaced
3658:02a1615d0392 | 3659:bb8a6df5ecba |
---|---|
117 if err then return false, err; end | 117 if err then return false, err; end |
118 if not uploads then return true; end | 118 if not uploads then return true; end |
119 uploads = array(uploads); | 119 uploads = array(uploads); |
120 local expiry = os.time() - max_age; | 120 local expiry = os.time() - max_age; |
121 local upload_window = os.time() - 900; | 121 local upload_window = os.time() - 900; |
122 local before = #uploads; | |
122 uploads:filter(function (item) | 123 uploads:filter(function (item) |
123 local filename = item.filename; | 124 local filename = item.filename; |
124 if item.dir then | 125 if item.dir then |
125 filename = join_path(storage_path, item.dir, item.filename); | 126 filename = join_path(storage_path, item.dir, item.filename); |
126 end | 127 end |
134 elseif item.time < upload_window and not lfs.attributes(filename) then | 135 elseif item.time < upload_window and not lfs.attributes(filename) then |
135 return false; -- File was not uploaded or has been deleted since | 136 return false; -- File was not uploaded or has been deleted since |
136 end | 137 end |
137 return true; | 138 return true; |
138 end); | 139 end); |
140 local after = #uploads; | |
141 if before == after then return true end -- nothing changed, skip write | |
139 return datamanager.list_store(username, host, module.name, uploads); | 142 return datamanager.list_store(username, host, module.name, uploads); |
140 end | 143 end |
141 | 144 |
142 local function check_quota(username, host, does_it_fit) | 145 local function check_quota(username, host, does_it_fit) |
143 if not quota then return true; end | 146 if not quota then return true; end |