We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit bf4c5cb4 authored by Evan Prodromou's avatar Evan Prodromou

Stream of notices linking to an URL

parent c8bbde69
......@@ -412,4 +412,69 @@ class File extends Memcached_DataObject
{
return File_thumbnail::staticGet('file_id', $this->id);
}
function blowCache($last=false)
{
self::blow('file:notice-ids:%s', $this->url);
if ($last) {
self::blow('file:notice-ids:%s;last', $this->url);
}
}
/**
* Stream of notices linking to this URL
*
* @param integer $offset Offset to show; default is 0
* @param integer $limit Limit of notices to show
* @param integer $since_id Since this notice
* @param integer $max_id Before this notice
*
* @return array ids of notices that link to this file
*/
function stream($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0)
{
$ids = Notice::stream(array($this, '_streamDirect'),
null,
'file:notice-ids:'.$this->url,
$offset, $limit, $since_id, $max_id);
return $ids;
}
/**
* Stream of notices linking to this URL
*
* @param integer $offset Offset to show; default is 0
* @param integer $limit Limit of notices to show
* @param integer $since_id Since this notice
* @param integer $max_id Before this notice
*
* @return array ids of notices that link to this file
*/
function _streamDirect($offset, $limit, $since_id, $max_id)
{
$f2p = new File_to_post();
$f2p->file_id = $this->id;
Notice::addWhereSinceId($f2p, $since_id, 'post_id', 'modified');
Notice::addWhereMaxId($f2p, $max_id, 'post_id', 'modified');
$f2p->orderBy('modified DESC, notice_id DESC');
if (!is_null($offset)) {
$reply->limit($offset, $limit);
}
$ids = array();
if ($f2p->find()) {
while ($f2p->fetch()) {
$ids[] = $f2p->notice_id;
}
}
return $ids;
}
}
......@@ -52,6 +52,12 @@ class File_to_post extends Memcached_DataObject
$f2p->file_id = $file_id;
$f2p->post_id = $notice_id;
$f2p->insert();
$f = File::staticGet($file_id);
if (!empty($f)) {
$f->blowNoticeCache();
}
}
if (empty($seen[$notice_id])) {
......@@ -66,4 +72,13 @@ class File_to_post extends Memcached_DataObject
{
return Memcached_DataObject::pkeyGet('File_to_post', $kv);
}
function delete()
{
$f = File::staticGet('id', $this->file_id);
if (!empty($f)) {
$f->blowNoticeCache();
}
return parent::delete();
}
}
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