From 85c8e395c60dda0f7000ac6a5342be92b7f56eb5 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Thu, 3 May 2018 20:04:28 +0200 Subject: file/clean_stale_files: Remove database entries without files Signed-off-by: Florian Pritz --- application/controllers/Main.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/application/controllers/Main.php b/application/controllers/Main.php index 6389b1039..28582d821 100644 --- a/application/controllers/Main.php +++ b/application/controllers/Main.php @@ -941,6 +941,25 @@ class Main extends MY_Controller { } closedir($outer_dh); + $chunk = 500; + $total = $this->db->count_all("file_storage"); + + for ($limit = 0; $limit < $total; $limit += $chunk) { + $query = $this->db->select('hash, id') + ->from('file_storage') + ->limit($chunk, $limit) + ->get()->result_array(); + + foreach ($query as $key => $item) { + $data_id = $item["hash"].'-'.$item['id']; + $file = $this->mfile->file($data_id); + + if (!$this->mfile->file_exists($file)) { + $this->mfile->delete_data_id($data_id); + } + } + } + // TODO: clean up special/multipaste-tarballs? cron() already expires // after a rather short time, do we really need this here then? } -- cgit v1.2.3-24-g4f1b