From 814c2b44fcc500d2f8f2acb7c9443079908ddaa2 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Wed, 8 Apr 2015 01:05:46 +0200 Subject: Cache filedata This brings down render time of a multipaste with 180 items from ~180ms to ~80ms. Signed-off-by: Florian Pritz --- application/models/mfile.php | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'application/models') diff --git a/application/models/mfile.php b/application/models/mfile.php index 724994f83..9af0ed497 100644 --- a/application/models/mfile.php +++ b/application/models/mfile.php @@ -69,18 +69,20 @@ class Mfile extends CI_Model { function get_filedata($id) { - $query = $this->db - ->select('id, hash, filename, mimetype, date, user, filesize') - ->from('files') - ->where('id', $id) - ->limit(1) - ->get(); - - if ($query->num_rows() > 0) { - return $query->row_array(); - } else { - return false; - } + return cache_function("filedata-$id", 300, function() use ($id) { + $query = $this->db + ->select('id, hash, filename, mimetype, date, user, filesize') + ->from('files') + ->where('id', $id) + ->limit(1) + ->get(); + + if ($query->num_rows() > 0) { + return $query->row_array(); + } else { + return false; + } + }); } // return the folder in which the file with $hash is stored @@ -214,6 +216,7 @@ class Mfile extends CI_Model { $this->db->where('id', $id) ->delete('files'); + delete_cache("filedata-$id"); foreach ($map as $entry) { assert(!empty($entry['url_id'])); -- cgit v1.2.3-24-g4f1b