From: Brion Vibber Date: Mon, 31 Jan 2011 20:22:50 +0000 (-0800) Subject: Use cachedQuery on File::getAttachments, plus other cleanups: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b896a37da0b2ce78802c3e0007084fe739b2ba0d;p=quix0rs-gnu-social.git 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. --- 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();