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:
parent
2a29738dc1
commit
b896a37da0
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user