From b896a37da0b2ce78802c3e0007084fe739b2ba0d Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 31 Jan 2011 12:22:50 -0800 Subject: [PATCH] Use cachedQuery on File::getAttachments, plus other cleanups: * dropped unnecessary join on notice table * made the function actually static, since it makes no sense as an instance variable. The only caller (in AttachmentList) is updated. --- classes/File.php | 18 ++++++++++++------ lib/attachmentlist.php | 3 +-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/classes/File.php b/classes/File.php index 29a8f0f1c5..e9a0131c4e 100644 --- a/classes/File.php +++ b/classes/File.php @@ -55,14 +55,20 @@ class File extends Memcached_DataObject return 'http://www.facebook.com/login.php' === $url; } - function getAttachments($post_id) { - $query = "select file.* from file join file_to_post on (file_id = file.id) join notice on (post_id = notice.id) where post_id = " . $this->escape($post_id); - $this->query($query); + /** + * Get the attachments for a particlar notice. + * + * @param int $post_id + * @return array of File objects + */ + static function getAttachments($post_id) { + $file = new File(); + $query = "select file.* from file join file_to_post on (file_id = file.id) where post_id = " . $file->escape($post_id); + $file = Memcached_DataObject::cachedQuery('File', $query); $att = array(); - while ($this->fetch()) { - $att[] = clone($this); + while ($file->fetch()) { + $att[] = clone($file); } - $this->free(); return $att; } diff --git a/lib/attachmentlist.php b/lib/attachmentlist.php index 7e536925bf..c3d3f4d116 100644 --- a/lib/attachmentlist.php +++ b/lib/attachmentlist.php @@ -76,8 +76,7 @@ class AttachmentList extends Widget */ function show() { - $atts = new File; - $att = $atts->getAttachments($this->notice->id); + $att = File::getAttachments($this->notice->id); if (empty($att)) return 0; $this->showListStart();