cache results of notice sitemap query

This commit is contained in:
Evan Prodromou 2010-04-12 11:52:19 -04:00
parent 610d8021d8
commit 946cd15e8b

View File

@ -84,8 +84,9 @@ class NoticesitemapAction extends SitemapAction
function getNotices($y, $m, $d, $i) function getNotices($y, $m, $d, $i)
{ {
$offset = ($i-1) * SitemapPlugin::NOTICES_PER_MAP; $n = Notice::cacheGet("sitemap:notice:$y:$m:$d:$i");
$limit = SitemapPlugin::NOTICES_PER_MAP;
if ($n === false) {
$notice = new Notice(); $notice = new Notice();
@ -95,7 +96,8 @@ class NoticesitemapAction extends SitemapAction
// with leap seconds (1d == 24h + 1s). Thankfully they're // with leap seconds (1d == 24h + 1s). Thankfully they're
// few and far between. // few and far between.
$enddt = common_sql_date(strtotime($begindt) + (24 * 60 * 60)); $theend = strtotime($begindt) + (24 * 60 * 60);
$enddt = common_sql_date($theend);
$notice->selectAdd(); $notice->selectAdd();
$notice->selectAdd('id, created'); $notice->selectAdd('id, created');
@ -107,6 +109,9 @@ class NoticesitemapAction extends SitemapAction
$notice->orderBy('created'); $notice->orderBy('created');
$offset = ($i-1) * SitemapPlugin::NOTICES_PER_MAP;
$limit = SitemapPlugin::NOTICES_PER_MAP;
$notice->limit($offset, $limit); $notice->limit($offset, $limit);
$notice->find(); $notice->find();
@ -117,6 +122,16 @@ class NoticesitemapAction extends SitemapAction
$n[] = array($notice->id, $notice->created); $n[] = array($notice->id, $notice->created);
} }
$c = Cache::instance();
if (!empty($c)) {
$c->set(Cache::key("sitemap:notice:$y:$m:$d:$i"),
$n,
Cache::COMPRESSED,
((time() > $theend) ? (time() + 90 * 24 * 60 * 60) : (time() + 5 * 60)));
}
}
return $n; return $n;
} }
} }