Commit b896a37d authored by Brion Vibber's avatar Brion Vibber

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.
parent 2a29738d
......@@ -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;
}
......
......@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment