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.
This commit is contained in:
Brion Vibber 2011-01-31 12:22:50 -08:00
parent 2a29738dc1
commit b896a37da0
2 changed files with 13 additions and 8 deletions

View File

@ -55,14 +55,20 @@ class File extends Memcached_DataObject
return 'http://www.facebook.com/login.php' === $url; 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); * Get the attachments for a particlar notice.
$this->query($query); *
* @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(); $att = array();
while ($this->fetch()) { while ($file->fetch()) {
$att[] = clone($this); $att[] = clone($file);
} }
$this->free();
return $att; return $att;
} }

View File

@ -76,8 +76,7 @@ class AttachmentList extends Widget
*/ */
function show() function show()
{ {
$atts = new File; $att = File::getAttachments($this->notice->id);
$att = $atts->getAttachments($this->notice->id);
if (empty($att)) return 0; if (empty($att)) return 0;
$this->showListStart(); $this->showListStart();