Comparison

plugins/mod_http_file_share.lua @ 11993:aa60f4353001

mod_http_file_share: Merge file expiry loops Not sure what the benefit of two separate loops was, perhaps reduced memory usage by allowing archive query state to be garbage collected before moving on to deleting files. Never measured so probably not so. This simplifies a bit.
author Kim Alvefur <zash@zash.se>
date Tue, 30 Nov 2021 00:53:22 +0100
parent 11992:876e1b6d6ae4
child 11994:f9b2325f6b50
comparison
equal deleted inserted replaced
11992:876e1b6d6ae4 11993:aa60f4353001
475 end 475 end
476 476
477 local obsolete_uploads = array(); 477 local obsolete_uploads = array();
478 local i = 0; 478 local i = 0;
479 local size_sum = 0; 479 local size_sum = 0;
480 local n = 0;
481 local problem_deleting = false;
480 for slot_id, slot_info in iter do 482 for slot_id, slot_info in iter do
481 i = i + 1; 483 i = i + 1;
482 obsolete_uploads:push(slot_id);
483 upload_cache:set(slot_id, nil); 484 upload_cache:set(slot_id, nil);
484 size_sum = size_sum + tonumber(slot_info.attr.size);
485 end
486
487 sleep(0.1);
488 local n = 0;
489 local problem_deleting = false;
490 obsolete_uploads:filter(function(slot_id)
491 n = n + 1;
492 if i % 100 == 0 then sleep(0.1); end
493 local filename = get_filename(slot_id); 485 local filename = get_filename(slot_id);
494 local deleted, err, errno = os.remove(filename); 486 local deleted, err, errno = os.remove(filename);
495 if deleted or errno == ENOENT then 487 if deleted or errno == ENOENT then
496 return true; 488 size_sum = size_sum + tonumber(slot_info.attr.size);
489 obsolete_uploads:push(slot_id);
497 else 490 else
498 module:log("error", "Could not delete file %q: %s", filename, err); 491 module:log("error", "Could not delete file %q: %s", filename, err);
499 problem_deleting = true; 492 problem_deleting = true;
500 return false; 493 end
501 end 494 if i % 100 == 0 then sleep(0.1); end
502 end); 495 end
496
503 -- obsolete_uploads now contains slot ids for which the files have been 497 -- obsolete_uploads now contains slot ids for which the files have been
504 -- deleted and that needs to be cleared from the database 498 -- deleted and that needs to be cleared from the database
505 499
506 local deletion_query = {["end"] = boundary_time}; 500 local deletion_query = {["end"] = boundary_time};
507 if not problem_deleting then 501 if not problem_deleting then